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
interfaceData{rootValue: number;nested: {nestedValue: string;}}// Problem lies heretypeTest<T>={[KinkeyofT]: TextendsRecord<string,unknown> ? Test<T[K]> : false;};// When using an interface, the mapped type for the nested field is incorrecttypeWithInterface=Test<Data>;typeNestedInWithInterface=WithInterface['nested'];// false// However when using a type directly it works as intendedtypeWithPlain=Test<{rootValue: number;nested: {nestedValue: string;}}>;typeNestedInWithPlain=WithPlain['nested'];// { nestedVaue: string }// Using a type instead of an interface also works as intendedtypeDataType={rootValue: number;nested: {nestedValue: string;}}typeWithType=Test<DataType>;typeNestedInWithType=WithType['nested'];// { nestedVaue: string }// And using another mapped type that's just an identity of the input also workstypeIdentity<T>={[KinkeyofT]: T[K]}typeWithInterfaceIdentity=Test<Identity<Data>>;typeNestedInWithInterfaceIdentity=WithInterfaceIdentity['nested'];// { nestedVaue: string }
π Actual behavior
When using a recursive mapped conditional type (not sure if I named it correctly), typescript breaks when using an interface as the generic parameter, but works when using inline types, type aliases and a mapped type.
π Expected behavior
Expected NestedInWithInterface to be { nestedVaue: string }, just like NestedInWithPlain, NestedInWithType, and NestedInWithInterfaceIdentity.
The text was updated successfully, but these errors were encountered:
ItsaMeTuni
changed the title
Recursive mapped conditional types not working when using interfaces
Recursive mapped conditional types not working when using interfaces (regression between 3.3.3 and 3.5.1)
Sep 13, 2022
Of course! It makes total sense, I can't believe I missed that and spent hours debugging this... Sorry about the trouble and thanks for the quick response.
Bug Report
π Search Terms
recursive mapped conditional types interface generic
π Version & Regression Information
β― Playground Link
Playground link with relevant code (version 3.3.3, working as intended)
Playground link with relevant code (version 3.5.1, breaking)
π» Code
π Actual behavior
When using a recursive mapped conditional type (not sure if I named it correctly), typescript breaks when using an interface as the generic parameter, but works when using inline types, type aliases and a mapped type.
π Expected behavior
Expected
NestedInWithInterface
to be{ nestedVaue: string }
, just likeNestedInWithPlain
,NestedInWithType
, andNestedInWithInterfaceIdentity
.The text was updated successfully, but these errors were encountered: