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
{{ message }}
Repository navigation
keyof FilteringMappedType can't compute its constraintΒ #56239
Type 'Values<{ [K in keyof TActors as K & string]: { src: K; logic: TActors[K]; }; }>' does not satisfy the constraint 'ProvidedActor'.
Types of property 'src' are incompatible.
Type 'keyof { [K in keyof TActors as K & string]: { src: K; logic: TActors[K]; }; }' is not assignable to type 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.(2344)
π Expected behavior
It should typecheck
Additional information about the issue
Almost the same thing typechecks OK if we refactor this to [K in keyof TActors & string].
Your case is working as expected. The constraint describes minimal requirement for the type - this is a valid type argument for your GetRecord: Record<PropertyKey, any>. So, as you can see, internally GetRecord can't assume that Key will be assignable to string
It seemes you are right. I've double-checked and Record creates somewhat open type, so type T5 = Record<number, any> extends Record<string, any> ? true : false is actually true. Object can be indexed by both.
Activity
StreetStrider commentedon Feb 10, 2025
I think I've found this as well (2025, TS@5.7.3)
To narrow down:
https://www.typescriptlang.org/play/?#code/FAFwngDgpgBASjAvPKBjA9gJwCYB4DOImAlgHYDmANDAIalgB8oksAKgIxIwDWUY6AM3jBm0GAHEoIANJ8YuWWBhQAHiCils+GIRIUGXRaLYAmLpJl9cvfkLhNjMVgGYuAbxgBtGIphkefILwMAC6AFwSUorWgXYGAL4i4GIWcGhY2PJpqMpqGlooGDgERGRUtPQMBsge3r7+NkHZoREW0YoJjqwALOZS2Rm49sBAA
where T1, T2 and T3 compute, while GetRecord not. T4 also compute, but it is based on GetRecord, so error would be present.
Andarist commentedon Feb 10, 2025
Your case is working as expected. The constraint describes minimal requirement for the type - this is a valid type argument for your
GetRecord:Record<PropertyKey, any>. So, as you can see, internallyGetRecordcan't assume thatKeywill be assignable tostringStreetStrider commentedon Feb 11, 2025
It seemes you are right. I've double-checked and Record creates somewhat open type, so
type T5 = Record<number, any> extends Record<string, any> ? true : falseis actuallytrue. Object can be indexed by both.Add regression tests for PR #60528