Closed
Description
Bug Report
With the strict null check turned on
function test(options?: { fields?: string , strict?: boolean}) {
options = Object.assign({ fields: null }, options);
if (options.fields) {
//^^^^^^^ Object is possibly 'undefined'.ts(2532)
}
const test2 = () => {
if (options.strict) {
//^^^^^^^ Object is possibly 'undefined'.ts(2532)
}
}
}
Any of the following changes fix the first (but not the second):
function test(options?: { fields?: string|null }) {
options = Object.assign({ fields: '' }, options);
options = Object.assign({ a:null }, options);
🔎 Search Terms
strictNullCheck, Object.assign
🕗 Version & Regression Information
4.1.3
⏯ Playground Link
💻 Code
🙁 Actual behavior
Wrongly assumes the options
can be undefined
🙂 Expected behavior
Should be no error
Metadata
Metadata
Assignees
Labels
No labels