-
Notifications
You must be signed in to change notification settings - Fork 12.8k
never extends ${infer P}
yield a different result than never extends ${infer P}/
#50215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This would seem to follow from the PR text
I don't really see a defect here; zero-length strings are weird to reason about and you could make an argument for changing either of these behaviors. Without a motivating use case to drive which one, changing it for the sake of changing it is just risk without benefit. |
What zero-length strings are we looking at here? Are you saying that we could interpret Would it be fair to say that one should have no particular expectations about what will come out of a pathological case like |
update: |
What? type M = never extends string ? true : false; // true |
@RyanCavanaugh lmao, sorry, had a brain fart |
Thinking about it more, I think the correct behavior is actually fairly straightforward when comparing this to object types (demonstrated below). Probably what's going wrong here is that we have an assumption somewhere that for any // A = true
type A = never extends { x: string } ? true : false;
// B = unknown
type B = never extends { x: infer T } ? T : "no";
// C = unknown
type C = never extends [infer T, unknown] ? T : "no";
// D = unknown
type D = never extends [unknown, infer T, unknown] ? T : "no";
// E = string
type E = never extends `${infer X}#` ? X : "no";
// F = never, ?. Should be 'string'
type F = never extends `${infer X}` ? X : "no"; |
sorry for that silly post, it is morning and my brain still being dumb ok long thing short I think it is normal to expect the P from never extends update: |
Bug Report
π Search Terms
never extends
${infer P}
yield different result than never extends${infer P}/
π Version & Regression Information
TS 4.7
type is not what expected
β― Playground Link
playground
π» Code
π Actual behavior
${infer P}/
yield the same result as never extends${infer P}
${infer P extends X}/
yield X but never extends${infer P extends X}
always yield neverπ Expected behavior
${infer P}/
should yield never like never extends${infer P}
${infer P extends X}/
yield never like never extends${infer P extends X}
are these intended behaviors? kind of unintuitive
The text was updated successfully, but these errors were encountered: