TypeScript/tests/cases/compiler/strictNullNotNullIndexTypeShouldWork.ts
Wesley Wigham 8212c962cd Workaround for nonnull operator on indexed accesses (#19275)
* Quick and dirty workaround

* Add third case to show current behavior

* Rename variable, replace elaboration from comment with links
2017-10-18 17:39:05 -07:00

33 lines
607 B
TypeScript

// @strictNullChecks: true
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
}
}