TypeScript/tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts

35 lines
676 B
TypeScript
Raw Normal View History

// @strictNullChecks: true
// @noLib: true
type Readonly<T> = {readonly [K in keyof T]: T[K]}
interface A {
params?: { name: string; };
}
class Test<T extends A> {
attrs: Readonly<T>;
m() {
this.attrs.params!.name;
}
}
interface Foo {
foo?: number;
}
class FooClass<P extends Foo = Foo> {
properties: Readonly<P>;
foo(): number {
const { foo = 42 } = this.properties;
return foo;
}
}
class Test2<T extends A> {
attrs: Readonly<T>;
m() {
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
}
}