-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Possible regression in error elaboration for optional properties #48083
Comments
Playgrounds nightly is over two weeks old. I've created microsoft/TypeScript-Website#2292. Most likely it's fixed on the next Playground deployment. The latest nightly (20220302) still has the issue you mention. |
I can see that there's some desire to talk about the possible values, but I'm tempted to say that this isn't a regression. It's intentional that we give simplified diagnostics that don't leak literal types when they're not helpful (preferring Maybe there's a middle ground here? Something to do with whether a type explicitly names |
type states = {
state1: string | undefined;
};
function x(y: states) {
return y;
}
x({ state1: true });
|
With just a small adjustment the type states = {
state1: string | number |undefined;
};
function x(y: states) {
return y;
}
x({ state1: true });
|
Bug Report
It is my understanding that PR #47738 made changes to the elaborations of certain error messages. For me it had an adverse effect in a somewhat simple use case that includes optional parameters passed to an object.
I tried reproducing it in the TS playground, but version 4.6 is not yet available there and the latest nightly playground build doesn't seem to include this change yet.
Getting the following error in v4.6.2:
Type 'boolean' is not assignable to type 'string'
The error in v4.5.5 used to be:
Type 'true' is not assignable to type 'string | undefined'
I'll note that this happens whether
undefined
is allowed explicitly in the type definition, or defined only as an optional parameter.🕗 Version & Regression Information
⏯ Playground Link
Here's a playground with the required setup, but as noted above, the playground doesn't seem to have the change that causes this issue yet.
Playground link with relevant code
💻 Code
🙁 Actual behavior
Error message ignores optional definition, or explicit undefined definition, and returns an error that only mentions the allowed primitives.
🙂 Expected behavior
Error message should mention
undefined
as an allowed value.The text was updated successfully, but these errors were encountered: