Given the following code:
interfaceWidget{x: number}declaretypeUnwrap<T>=TextendsPromise<infer U1> ? UnwrapSimple<U1> : UnwrapSimple<T>;declaretypeprimitive=Function|string|number|boolean|undefined|null;declaretypeUnwrapSimple<T>=Textendsprimitive ? T : TextendsArray<infer U> ? UnwrappedArray<U> : Textendsobject ? UnwrappedObject<T> : never;exportinterfaceUnwrappedArray<T>extendsArray<Unwrap<T>>{}exportdeclaretypeUnwrappedObject<T>={[PinkeyofT]: Unwrap<T[P]>;};declarevarw: Widget;declaretypeTupleType=[Widget,string];declarevaro: UnwrappedObject<TupleType>;TypeScript oddly infers a type of [any, string] for o. This is surprising to us given how we would think these type operators would work. First, given the definition UnwrappedObject i would expect UnwrappedObject<TupleType> to expand like so:
UnwrappedObject<TupleType> ->
UnwrappedObject<[Widget, string]> ->
[Unwrap<Widget>, Unwrap<string>] ->
[UnwrappedObject<Widget>, string] ->
[{ x: Unwrap<number> }, string] ->
[{ x: number }, string]
HOwever, instead of getting { x: number } (which is just the Widget type), we end up with 'any'. Cany anyone shed any light on this? Thanks!
Given the following code:
TypeScript oddly infers a type of
[any, string]foro. This is surprising to us given how we would think these type operators would work. First, given the definitionUnwrappedObjecti would expectUnwrappedObject<TupleType>to expand like so:HOwever, instead of getting
{ x: number }(which is just the Widget type), we end up with 'any'. Cany anyone shed any light on this? Thanks!