TypeScript Version: 3.5.1
Code
interface DataType{
display_name: string | null
}
function myName(data :DataType) : string{
if( !!data.display_name === false ) return 'No Name'
return data.display_name
}
Expected behavior:
Typescript shouldn't complain about return data.display_name because I covered the null before this.
Actual behavior:
It saying Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'. on return data.display_name
Playground Link:
You can see the result here.
TypeScript Version: 3.5.1
Code
Expected behavior:
Typescript shouldn't complain about
return data.display_namebecause I covered thenullbefore this.Actual behavior:
It saying
Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.onreturn data.display_namePlayground Link:
You can see the result here.