exactOptionalPropertyTypes adds `undefined` to `Required` types in JavaScript but not in TypeScript.
Bug Report
🔎 Search Terms
required undefined javascript
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
required
⏯ Playground Link
💻 Code
/**
* @typedef Foo
* @property {number} [foo]
*/
const x = /** @type {Foo} */ ({});
x.foo; // number | undefined
const y = /** @type {Required<Foo>} */ ({});
y.foo; // number | undefined
🙁 Actual behavior
There's a mismatch between the JavaScript and TypeScript behaviour which I think is unintentional.
y.foo has type number | undefined in JavaScript but in TypeScript its type is number.
🙂 Expected behavior
I'm guessing JavaScript has the incorrect behaviour here. So in that case the expected result would be just number.
I think this issue is related to https://github.com/microsoft/TypeScript/issues/49080. I've added an additional test to https://github.com/microsoft/TypeScript/pull/49910
/cc @RyanCavanaugh @sandersn
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.