Skip to content

Instantly share code, notes, and snippets.

const someVariable: {
prop1: "value1",
props2: "value2",
nestedType: {
nestedProps: "nested value",
...
},
...
}
// ------- 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;
@cenkce
cenkce / tuple-operators.ts
Created February 22, 2020 23:08
Typescript Tuple Operators
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>>;
@cenkce
cenkce / tuple-test.ts
Last active February 23, 2020 08:42
Test of Tuple Operators
type TestTuple = [
"key1",
"union type 1" | "union type 2" | "union type 3",
"key2",
string,
"key3",
number,
"key4",
[string, number, null | string]
];
@cenkce
cenkce / tuple-operators-examples.ts
Last active February 23, 2020 08:44
Tuple Operators Examples
// ... 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) {