Created
March 25, 2019 19:07
-
-
Save fvilante/9b539b70609047d55378f0ede54e64a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
const Url = | |
Safe<string>({ | |
validation: [] //fix: introduce validation | |
validOperations: [getfullPath] | |
} | |
*/ | |
// assures T is a primitive type | |
type TPrimitive<T> = | |
T extends number ? number : | |
T extends string ? string : | |
// object, array, etc . . . | |
// else | |
never | |
type Safe<TKey extends string, T> = { | |
key: TKey | |
value: TPrimitive<T> | |
} | |
const Safe = | |
<Tkey extends string, T > | |
(key: Tkey) => | |
(value: TPrimitive<T>) => | |
({ key, value }) | |
// boler-plate | |
type Url = ReturnType<typeof Url> | |
type Product = {name: string} | |
// Glossary | |
const Url = | |
Safe<"Url", string>("Url") | |
type Products = | |
ReadonlyArray<Product> | |
const noData = | |
undefined | |
type Method = | |
| "GET" | |
| "POST" | |
| "PUT" | |
type RequestOrder = | |
[Method, Url] | |
const site = | |
Url('www.foo.com') | |
// operations | |
const urlRequest = | |
<TResult, TData> | |
(baseUrl: Url) => | |
(data: TData) => | |
(request: RequestOrder): | |
Promise<TResult> => { | |
return new Promise<TResult>(x => x) | |
} | |
const urlRequestOrder = | |
urlRequest(site)(noData) | |
// Order's request | |
const allProducst = | |
["GET", Url()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment