-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
infer, keyof, string, interpolation, union, all keys, too big, too wide
π Version & Regression Information
Syntax not supported before 4.7
Similar behavior on all versions upwards
β― Playground Link
π» Code
type D0 = {
a: '0',
b: '1',
c: '2'
};
type D1 = {
aa: '0',
b: '1',
c: '2'
};
type Test<Data, T> = T extends `${infer K extends keyof Data & string}${string}` ? K : false;
type T0 = Test<D0, 'aXXX'>; // 'a'
type T1 = Test<D1, 'aaXXX'>; // 'b'|'c'|'aa'
π Actual behavior
T1 is the union of all keys of D1 while only one fits within the pattern.
The extra keys are irrelevant.
The inference is not helpful.
This behavior seems inconsistent since T0 gives the expected key.
π Expected behavior
T1 = 'aa'
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created