You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript Version: 2.3 (the one in the playground)
Code
interfaceIName{name?: string;}classA{prop: IName;constructor(param: IName){this.prop=param;}printProp(){if(this.prop){// this.prop = undefined; // TS will catch this errordeletethis.prop;// Oh no, now we'll have a runtime errorconsole.log(this.prop.name);}}}consta=newA({name: 'a'});a.printProp();
Should warn us about using the delete operator since we told typescript that prop is an IName.
Actual behavior:
Currently as the code stands typescript is not able to warn us of the oncoming failure. I have left the line this.prop = undefined and typescript will complain about it. Using the delete operator will do the same as setting as undefined but there is no warning.
Make sure to use the strictNullChecks option when running the code.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.3 (the one in the playground)
Code
Or click here to see it in the playground.
Expected behavior:
Should warn us about using the delete operator since we told typescript that
prop
is anIName
.Actual behavior:
Currently as the code stands typescript is not able to warn us of the oncoming failure. I have left the line
this.prop = undefined
and typescript will complain about it. Using thedelete
operator will do the same as setting as undefined but there is no warning.Make sure to use the
strictNullChecks
option when running the code.The text was updated successfully, but these errors were encountered: