TypeScript/tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts
Wesley Wigham 2f0a13c7c3
Use global NonNullable type for nonnull types (#22096)
* Use NonNullable type for nonnull types

* Add noLib test

* Remove conditional type fallback for when lib is not present
2018-03-05 14:52:06 -08:00

35 lines
676 B
TypeScript

// @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
}
}