Consider the following abstract class:
export abstract class Foo {
abstract bar(param: string | null): string
}
Changing the parameter to be non-nullable in a concrete implementation does not cause a type error. This is unexpected.
export class ConcreteFoo extends Foo {
bar(param: string): string {
return param
}
}
This allows me to do:
const inst = new ConcreteFoo() as Foo
const res = inst.bar(null)
console.log(res) // res is null, but typescript says it is string
Why is this possible?
Strict null checks are on. Typescript version is 4.5.3.