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
// ... import types | |
type ComponentProps: { | |
EnvironmentVariable: TestListToUnion // [] | ["key1", "union type 1" | "union type 2" | "union type 3"] | ["key2", string] | ["key3", number] ... | |
EnvironmentVariables: TestListToTypeAlias // {key4: "type of string";} & {key3: number;} ... | |
SelectedEnvironmentVariableKey: TestKeys // "key1" | "key2" | "key3" | "key4" | undefined | |
... | |
} | |
function Component(props: ComponentProps) { |
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
type TestTuple = [ | |
"key1", | |
"union type 1" | "union type 2" | "union type 3", | |
"key2", | |
string, | |
"key3", | |
number, | |
"key4", | |
[string, number, null | string] | |
]; |
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
type SliceTuple< | |
T extends any[], | |
TMaxItem extends number = 2, | |
R extends any[] = [], | |
P extends any[] = [], | |
I extends any[] = [] | |
> = { | |
0: SliceTuple<T, TMaxItem, R, Prepend<T[Pos<I>], P>, Next<I>>; | |
1: Reverse<Prepend<Reverse<P>, R>>; | |
2: SliceTuple<T, TMaxItem, Prepend<Reverse<P>, R>, [T[Pos<I>]], Next<I>>; |
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
// ------- Typing Operators ------- | |
// https://github.com/pirix-gh/medium/blob/master/types-curry-ramda/src/index.ts | |
export type Iterator< | |
Index extends number = 0, | |
From extends any[] = [], | |
I extends any[] = [] | |
> = { | |
0: Iterator<Index, Next<From>, Next<I>>; | |
1: From; |
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 someVariable: { | |
prop1: "value1", | |
props2: "value2", | |
nestedType: { | |
nestedProps: "nested value", | |
... | |
}, | |
... | |
} |
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
// Extracts only non nested values | |
type ExtractValue<T extends {[key:string]: any}> = T extends {[key:string]: any} ? T[keyof T] : T; | |
// Recusively extracts values | |
type ExtractValues<T extends {[key:string]: any}> = T extends {[key:string]: any} ? ExtractValue<T[keyof T]> : never; | |
type ValuesOfComplexType = ExtractValues<ComplexType>; | |
// or | |
type ValuesOfComplexType = ExtractValues<typeof ComplexConstants>; | |
// assings the values | |
// "any value 1" | "any value 2" | "any value 3" | "any value 4" ... |
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
type ValuesOfType = "any prop 1" | "any prop 2" | "any prop 3" // ... |
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
// We can't pass single provider name like Facebook | |
// Because it waits a complete object of the complexDataType | |
declare function share(provider: complexDataType):void; |
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 shareLinks: { | |
socialMedia: { | |
twitter: "twitter", | |
facebook: "facebook" | |
}, | |
email: "email", | |
anotherWay: "anotherWay" | |
} | |
// or more complex types |
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 firstArray = ['a', 'b', 'c', 'd', 'e']; | |
const secondArray = ['a', 'b', 'c', 'x', 'a', 'k', 'x','a','r']; | |
const acc = {}; | |
const table = {}; | |
function explore(val){ | |
if(val !== undefined && !acc[val]){ | |
table[val] = true; | |
} else if(val !== undefined) { |
NewerOlder