TypeScript Version: 3.5.0-dev.20190420
Search Terms:Object is possibly 'undefined'
Code
interfaceSomeObject{prop: string}interfaceSomeComplexObject{prop: SomeObject}exportclassSomeClass{privateprop: String;publicconstructor(someParam?: SomeObject,someOtherParam?: SomeComplexObject){if(someParam===undefined&&someOtherParam===undefined){// <1>thrownewError("One of the params must be provided.");}elseif(someOtherParam!==undefined){// <2>someParam=someOtherParam.prop;}// If someParam === undefined, someOtherParam === undefined, it should goes to <1> and throw;// If someParam === undefined, it should goes to <2>, then someParam will be assigned with a non-undefined value, then goes to <3>;// If someParam !== undefined, it should goes to <3> directly and should not generate any error.// <3>this.prop=someParam.prop;// ↑ Object is possibly 'undefined'.ts(2532)}}Expected behavior:
someParam won't be undefined and its props can be accessed
Actual behavior:
Compiler complains Object is possibly 'undefined'
Playground Link:Playground (Need to check strictNullCheck)
Related Issues: Not yet
TypeScript Version: 3.5.0-dev.20190420
Search Terms:
Object is possibly 'undefined'Code
Expected behavior:
someParamwon't beundefinedand its props can be accessedActual behavior:
Compiler complains
Object is possibly 'undefined'Playground Link:Playground (Need to check strictNullCheck)
Related Issues: Not yet