Closed
Description
TypeScript Version: 3.7.2
Search Terms:
NonNullable this this[] this property nonnullable
Code
type SomeType = string | undefined
class Test {
prop: SomeType
func1 = (): this['prop'] => {
return this.prop
}
func2 = (): SomeType => {
return this.prop
}
func3 = (): NonNullable<this['prop']> => {
return this.prop!
}
func4 = (): NonNullable<SomeType> => {
return this.prop!
}
}
Expected behavior:
This code compiles correctly, this['prop']
and SomeType
point to the same type.
Actual behavior:
func3
is not happy with the return statement: Type 'string' is not assignable to type 'NonNullable<this["prop"]>'
.
Playground Link: link
Related Issues: none