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
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABFApgZygCjgB1gtAfgC5EBvRYGFAGwBMjSMAnGMAcwBpEWZoTEAIzhwaKAIZIAvgEpyAKERLEufGDSIAvIgDyggFYpoAOnFo0MdmEwUqtBqTAgaNRFO6r46mQG5FymGBEbDwvNGM7ejQ5Mn9lZQB6BIA9VLTk3QMjKEQYDRw4cxhBGgBPRABycDoUKjAUOgrjKDRMACYAVgBmNpk4t36IAhzUDDatYLlNAD4FePmAoJC1cN5oGP6FhaT0tMzDaFz8wosS8qqwGrqGppb27t7Nral+l6kgA
💻 Code
🙁 Actual behavior
Wrongly assumes the options can be undefined
🙂 Expected behavior
Should be no error
Bug Report
With the strict null check turned on
Any of the following changes fix the first (but not the second):
🔎 Search Terms
strictNullCheck, Object.assign
🕗 Version & Regression Information
4.1.3
⏯ Playground Link
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABFApgZygCjgB1gtAfgC5EBvRYGFAGwBMjSMAnGMAcwBpEWZoTEAIzhwaKAIZIAvgEpyAKERLEufGDSIAvIgDyggFYpoAOnFo0MdmEwUqtBqTAgaNRFO6r46mQG5FymGBEbDwvNGM7ejQ5Mn9lZQB6BIA9VLTk3QMjKEQYDRw4cxhBGgBPRABycDoUKjAUOgrjKDRMACYAVgBmNpk4t36IAhzUDDatYLlNAD4FePmAoJC1cN5oGP6FhaT0tMzDaFz8wosS8qqwGrqGppb27t7Nral+l6kgA
💻 Code
🙁 Actual behavior
Wrongly assumes the
optionscan be undefined🙂 Expected behavior
Should be no error