Description
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
- This changed between versions 4.5.5 and 4.6
⏯ 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
type states = {
state1?: string | undefined;
};
function x(y: states) {}
x({ state1: true });
🙁 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.