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
typeStringProps<Entity>={[KinkeyofEntityasEntity[K]extendsstring ? K : never]: Entity[K];};typeStringPropKey<Entity>=keyofStringProps<Entity>;functionlogKey<E>(key: StringPropKey<E>){console.log(key);}functionerror<Eextends{uuid: string}>(){logKey<E>('uuid');}
π Actual behavior
Compilation error: Argument of type 'string' is not assignable to parameter of type 'keyof StringProps<E>'. Type '"uuid"' is not assignable to type '(E[K] extends string ? K : never) | (E["uuid"] extends string ? "uuid" : never)'
π Expected behavior
There should not be a compilation error. As a workaround, we can explicitly check if E extends { uuid: string }:
functionerror<Eextends{uuid: string}>(){// thislogKey<Eextends{uuid: string} ? E : never>('uuid');}
but this should not be required because E already extends { uuid: string }.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
"generic type inference"
π Version & Regression Information
TS v5.3.3
It's not a regression.
β― Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAysBOBLAdgcwArwPZgM4B4BRZYRUAPigF4oBvAKCigG0BpKFKAawhCwDMoxUqCgBDXEJJkQbALpQIAD2ARkAE0m4EKVFAD8UdgC4oyCADcI8OaeEz5AbnoBfZ-VCRYOtJhyteImkKam5eAW8kX2w8IJEQcnd+AFdkAGNSLGQoABssVACQInIACh4QUzgojBjC4oBKOkYoNKzcLByIADo81DLeeucXenoU9Mzs62x4IkUVNU06KGTkxHVTbWqoF1LGhiZeusJSgHIVtZPB13ogA
π» Code
π Actual behavior
Compilation error:
Argument of type 'string' is not assignable to parameter of type 'keyof StringProps<E>'. Type '"uuid"' is not assignable to type '(E[K] extends string ? K : never) | (E["uuid"] extends string ? "uuid" : never)'
π Expected behavior
There should not be a compilation error. As a workaround, we can explicitly check if
E extends { uuid: string }
:but this should not be required because
E
already extends{ uuid: string }
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: