Closed as not planned
Closed as not planned
Description
Bug Report
π Search Terms
- Object entries optional properties
- Object values optional properties
π Version & Regression Information
- This changed between versions 4.2.3 and 4.3.5
β― Playground Link
- 4.2.3 Playground link producing type error as expected
- 4.3.5 Playground link not producing type error anymore
π» Code
// without tsconfig.json#exactOptionalPropertyTypes enabled, optional properties can exist with `undefined`
const obj: {foo?: string, bar?: string} = {foo: undefined, bar: undefined}
Object.entries(obj).forEach(([key, value]) => {
const str: string = value; // value should be recognised as potentially undefined
})
Object.values(obj).forEach(value => {
const str: string = value; // value should be recognised as potentially undefined
})
π Actual behavior
From v4.3 it doesnt consider optional object properties as potentially undefined (with exactOptionalPropertyTypes disabled) when using Object#entries
or Object#values
π Expected behavior
Optional properties should mean the value when using Object#entries
or Object#values
is potentially undefined when exactOptionalPropertyTypes is disabled, as undefined
could be assigned to the optional properties.
This allows TS to compile code with potential runtime issues from using optional properties as if they were always defined.