Last active
February 23, 2020 08:42
-
-
Save cenkce/485d4f81dff541c014680a7595f6e6dd to your computer and use it in GitHub Desktop.
Test of Tuple Operators
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] | |
]; | |
type TestSlicedTuple = SliceTuple<TestTuple, 2>; | |
// result is [["key1", "union type 1" | "union type 2" | "union type 3"], ["key2", string], ["key3", number], ["key4", [string, number, string | null]]] | |
type TestSlicedTupleItem = TestSlicedTuple[0]; | |
// result is ["key1", "union type 1" | "union type 2" | "union type 3"] | |
type TestListToTypeAlias = MergeTuple<TestSlicedTuple>; | |
// result is [string, number, string | null]; & {key3: number;} & {key2: string;} & {key1: "type 1";}; | |
// result is equal to {key4: "an another type"; key3: number; key2: string; key1: "type 1";} | |
type TestListToUnion = PipeTuple<TestSlicedTuple>; | |
// result is [] | ["key1", "union type 1" | "union type 2" | "union type 3"] | ["key2", string] | ["key3", number] | ["key4", [string, number, string | null]] | |
type TestAlias = TestListToTypeAlias["key4"]; | |
// result is [string, number, string | null] | |
type TestKeys = TestListToUnion[0]; | |
// result is "key1" | "key2" | "key3" | "key4" | undefined | |
type TestTypes = TestListToUnion[1]; | |
// result is string | number | [string, number, string | null] | undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment