You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeNestedKeyOf<Type>=Typeextendsstring|number
? never
: {[KeyinTraversableKeys<Type>]: NestedSingleKeyOf<Type,Key>;}[TraversableKeys<Type>];typeTraversableKeys<Type>=Exclude<keyofType&(string|number),'prototype'>;typeNestedSingleKeyOf<Type,KeyextendskeyofType>=Keyextendsstring
? IsArray<Type[Key],Key| `${Key}.${number}`,IsComplexObject<Type[Key],Key| `${Key}.${NestedKeyOf<Type[Key]>}`,Key>>
: never;typeIsArray<O,T,F>=OextendsArray<unknown> ? T : F;typeIsComplexObject<O,T,F>=OextendsDate|Array<unknown>|Blob
? F
: IsObject<O,T,F>;typeIsObject<O,T,F>=Oextendsobject ? T : F;
for NestedValueOf
typeNestedValueOf<Type,Keyextendsstring>=Keyextends `${infer Head}.${infer Tail}`
? HeadextendskeyofType
? IsNumberFromString<Tail,IsArrayValue<Type[Head],NestedValueOf<Type[Head],Tail>>,NestedValueOf<Type[Head],Tail>>
: never
: IsKeyOfType<Type,Key>;typeIsArrayValue<O,F>=OextendsArray<infer U> ? U : F;typeIsNumberFromString<O,T,F>=Oextends `${number}` ? T : F;typeIsKeyOfType<Type,Key>=KeyextendskeyofType ? Type[Key] : never;
This way, the type of 'value' is correctly inferred in the callback. I can even access different levels of nesting using dots, such as 'field1.field1-2.field1-2-1,' or even array positions, inferring the correct type like 'field1.6'.
From this point, my problem is that in cases with multiple levels of nesting (3 or more) and types with many properties (20–30 or more), it takes a long time to compute the corresponding type. Is there any way to optimize the typing or handle it differently?
The text was updated successfully, but these errors were encountered:
Acknowledgement
Comment
I have been trying to use type inference for a specific case.
In 'transformation,' I would like 'value' to be of type Date instead of being number | Date.
To achieve this, I created two helper types to get the union of possible 'field' types and to correctly infer the type from 'field' in the callback.
for NestedKeyOf
for NestedValueOf
This way, the type of 'value' is correctly inferred in the callback. I can even access different levels of nesting using dots, such as 'field1.field1-2.field1-2-1,' or even array positions, inferring the correct type like 'field1.6'.
From this point, my problem is that in cases with multiple levels of nesting (3 or more) and types with many properties (20–30 or more), it takes a long time to compute the corresponding type. Is there any way to optimize the typing or handle it differently?
The text was updated successfully, but these errors were encountered: