Created
June 9, 2020 21:34
-
-
Save VitorLuizC/90504dd4b82986f78a2af3f6aa0da6ae to your computer and use it in GitHub Desktop.
This file contains 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 JsonObject = { [property: string]: Json }; | |
type JsonArray = Json[]; | |
type Json = null | boolean | number | string | JsonObject | JsonArray; | |
type NodeOf<T extends Json> = T extends JsonObject | |
? T | |
: T extends JsonArray | |
? T[number] | |
: never; | |
type X = { | |
property1: string; | |
property2: null; | |
property3: string; | |
property4: boolean; | |
property5: boolean; | |
property6: number; | |
property7: { | |
name: string; | |
}; | |
}; | |
type XNode = NodeOf<X[keyof X]>; | |
//=> { name: string; } | |
type Y = { | |
property1: number; | |
property2: null; | |
property3: string; | |
property4: boolean; | |
property5: boolean; | |
property6: number[]; | |
property7: { | |
value: number; | |
}[]; | |
}; | |
type YNode = NodeOf<Y[keyof Y]>; | |
//=> { value: number } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment