Closed as not planned
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment