From 060f0b2b0405dab2a82b1e5a4f9f44fe248598e2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 21 Feb 2018 13:50:02 -0800 Subject: [PATCH 1/3] Use NonNullable type for nonnull types --- src/compiler/checker.ts | 30 +++++++++++++++++-- ...terExtendingStringAssignableToString.types | 10 +++---- ...strictNullNotNullIndexTypeShouldWork.types | 14 ++++----- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2fcc924a7b8af..357b87b6151a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -400,6 +400,10 @@ namespace ts { let anyArrayType: Type; let autoArrayType: Type; let anyReadonlyArrayType: Type; + let deferredGlobalNonNullableTypeAlias: Symbol; + let deferredGlobalNonNullableTypeFallback: Type; + let deferredGlobalNonNullableTypeFallbackInstantiationCache: Map; + let deferredGlobalNonNullableTypeParameterFallback: TypeParameter; // The library files are only loaded when the feature is used. // This allows users to just specify library files they want to used through --lib @@ -11037,8 +11041,31 @@ namespace ts { return type.flags & TypeFlags.Undefined ? type : getUnionType([type, undefinedType]); } + function getGlobalNonNullableTypeInstantiation(type: Type) { + if (!deferredGlobalNonNullableTypeAlias) { + deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable" as __String, SymbolFlags.TypeAlias, /*diagnostic*/ undefined) || unknownSymbol; + } + // Use NonNullable global type alias if available to improve quick info/declaration emit + if (deferredGlobalNonNullableTypeAlias !== unknownSymbol) { + return getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]); + } + if (!deferredGlobalNonNullableTypeFallback) { + const p = deferredGlobalNonNullableTypeParameterFallback = createType(TypeFlags.TypeParameter) as TypeParameter; + deferredGlobalNonNullableTypeFallback = getConditionalType(p, getUnionType([nullType, undefinedType]), neverType, p, /*inferTypeParameters*/ undefined, /*target*/ undefined, /*mapper*/ undefined, /*alias*/ undefined, /*aliasTypeArguments*/ undefined); + deferredGlobalNonNullableTypeFallbackInstantiationCache = createMap(); + } + // Fallback to manufacturing an anonymous conditional type instantiation + const args = [type]; + const id = getTypeListId(args); + let instantiation = deferredGlobalNonNullableTypeFallbackInstantiationCache.get(id); + if (!instantiation) { + deferredGlobalNonNullableTypeFallbackInstantiationCache.set(id, instantiation = instantiateType(deferredGlobalNonNullableTypeFallback, createTypeMapper([deferredGlobalNonNullableTypeParameterFallback], [type]))); + } + return instantiation; + } + function getNonNullableType(type: Type): Type { - return strictNullChecks ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; + return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type; } /** @@ -13314,7 +13341,6 @@ namespace ts { return parent.kind === SyntaxKind.PropertyAccessExpression || parent.kind === SyntaxKind.CallExpression && (parent).expression === node || parent.kind === SyntaxKind.ElementAccessExpression && (parent).expression === node || - parent.kind === SyntaxKind.NonNullExpression || parent.kind === SyntaxKind.BindingElement && (parent).name === node && !!(parent).initializer; } diff --git a/tests/baselines/reference/nonNullParameterExtendingStringAssignableToString.types b/tests/baselines/reference/nonNullParameterExtendingStringAssignableToString.types index 9ab1ef1f9ac68..8590db628d0df 100644 --- a/tests/baselines/reference/nonNullParameterExtendingStringAssignableToString.types +++ b/tests/baselines/reference/nonNullParameterExtendingStringAssignableToString.types @@ -23,18 +23,18 @@ function fn(one: T, two: U) { foo(one!); >foo(one!) : void >foo : (p: string) => void ->one! : string ->one : string | undefined +>one! : NonNullable +>one : T foo(two!); >foo(two!) : void >foo : (p: string) => void ->two! : U +>two! : NonNullable >two : U foo(three!); // this line is the important one >foo(three!) : void >foo : (p: string) => void ->three! : string ->three : string +>three! : NonNullable | NonNullable +>three : T | U } diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeShouldWork.types b/tests/baselines/reference/strictNullNotNullIndexTypeShouldWork.types index e401a3d4950c0..774314ee8a358 100644 --- a/tests/baselines/reference/strictNullNotNullIndexTypeShouldWork.types +++ b/tests/baselines/reference/strictNullNotNullIndexTypeShouldWork.types @@ -22,12 +22,12 @@ class Test { this.attrs.params!.name; >this.attrs.params!.name : string ->this.attrs.params! : { name: string; } ->this.attrs.params : { name: string; } | undefined +>this.attrs.params! : NonNullable +>this.attrs.params : T["params"] >this.attrs : Readonly >this : this >attrs : Readonly ->params : { name: string; } | undefined +>params : T["params"] >name : string } } @@ -76,14 +76,14 @@ class Test2 { >T : T m() { ->m : () => { name: string; } +>m : () => NonNullable return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally ->this.attrs.params! : { name: string; } ->this.attrs.params : { name: string; } | undefined +>this.attrs.params! : NonNullable +>this.attrs.params : T["params"] >this.attrs : Readonly >this : this >attrs : Readonly ->params : { name: string; } | undefined +>params : T["params"] } } From 67014b04ca37321412b6245ab44451e01f4e4c33 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 21 Feb 2018 15:42:14 -0800 Subject: [PATCH 2/3] Add noLib test --- ...strictNullNotNullIndexTypeNoLib.errors.txt | 52 ++++++++++ .../strictNullNotNullIndexTypeNoLib.js | 61 ++++++++++++ .../strictNullNotNullIndexTypeNoLib.symbols | 94 ++++++++++++++++++ .../strictNullNotNullIndexTypeNoLib.types | 97 +++++++++++++++++++ .../strictNullNotNullIndexTypeNoLib.ts | 35 +++++++ 5 files changed, 339 insertions(+) create mode 100644 tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt create mode 100644 tests/baselines/reference/strictNullNotNullIndexTypeNoLib.js create mode 100644 tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols create mode 100644 tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types create mode 100644 tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt new file mode 100644 index 0000000000000..9f4651b07c3fb --- /dev/null +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt @@ -0,0 +1,52 @@ +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'RegExp'. +error TS2318: Cannot find global type 'String'. + + +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'RegExp'. +!!! error TS2318: Cannot find global type 'String'. +==== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts (0 errors) ==== + type Readonly = {readonly [K in keyof T]: T[K]} + interface A { + params?: { name: string; }; + } + + class Test { + attrs: Readonly; + + m() { + this.attrs.params!.name; + } + } + + interface Foo { + foo?: number; + } + + class FooClass

{ + properties: Readonly

; + + foo(): number { + const { foo = 42 } = this.properties; + return foo; + } + } + + class Test2 { + attrs: Readonly; + + m() { + return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally + } + } \ No newline at end of file diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.js b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.js new file mode 100644 index 0000000000000..42a8b07091add --- /dev/null +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.js @@ -0,0 +1,61 @@ +//// [strictNullNotNullIndexTypeNoLib.ts] +type Readonly = {readonly [K in keyof T]: T[K]} +interface A { + params?: { name: string; }; +} + +class Test { + attrs: Readonly; + + m() { + this.attrs.params!.name; + } +} + +interface Foo { + foo?: number; +} + +class FooClass

{ + properties: Readonly

; + + foo(): number { + const { foo = 42 } = this.properties; + return foo; + } +} + +class Test2 { + attrs: Readonly; + + m() { + return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally + } +} + +//// [strictNullNotNullIndexTypeNoLib.js] +var Test = /** @class */ (function () { + function Test() { + } + Test.prototype.m = function () { + this.attrs.params.name; + }; + return Test; +}()); +var FooClass = /** @class */ (function () { + function FooClass() { + } + FooClass.prototype.foo = function () { + var _a = this.properties.foo, foo = _a === void 0 ? 42 : _a; + return foo; + }; + return FooClass; +}()); +var Test2 = /** @class */ (function () { + function Test2() { + } + Test2.prototype.m = function () { + return this.attrs.params; // Return type should maintain relationship with `T` after being not-null-asserted, ideally + }; + return Test2; +}()); diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols new file mode 100644 index 0000000000000..a41798f2f521b --- /dev/null +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols @@ -0,0 +1,94 @@ +=== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts === +type Readonly = {readonly [K in keyof T]: T[K]} +>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14)) +>K : Symbol(K, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 30)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14)) +>K : Symbol(K, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 30)) + +interface A { +>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50)) + + params?: { name: string; }; +>params : Symbol(A.params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) +>name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14)) +} + +class Test { +>Test : Symbol(Test, Decl(strictNullNotNullIndexTypeNoLib.ts, 3, 1)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 11)) +>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50)) + + attrs: Readonly; +>attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25)) +>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 11)) + + m() { +>m : Symbol(Test.m, Decl(strictNullNotNullIndexTypeNoLib.ts, 6, 23)) + + this.attrs.params!.name; +>this.attrs.params!.name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14)) +>this.attrs.params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) +>this.attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25)) +>this : Symbol(Test, Decl(strictNullNotNullIndexTypeNoLib.ts, 3, 1)) +>attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25)) +>params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) +>name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14)) + } +} + +interface Foo { +>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1)) + + foo?: number; +>foo : Symbol(Foo.foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 13, 15)) +} + +class FooClass

{ +>FooClass : Symbol(FooClass, Decl(strictNullNotNullIndexTypeNoLib.ts, 15, 1)) +>P : Symbol(P, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 15)) +>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1)) +>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1)) + + properties: Readonly

; +>properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37)) +>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0)) +>P : Symbol(P, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 15)) + + foo(): number { +>foo : Symbol(FooClass.foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 18, 28)) + + const { foo = 42 } = this.properties; +>foo : Symbol(foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 21, 15)) +>this.properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37)) +>this : Symbol(FooClass, Decl(strictNullNotNullIndexTypeNoLib.ts, 15, 1)) +>properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37)) + + return foo; +>foo : Symbol(foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 21, 15)) + } +} + +class Test2 { +>Test2 : Symbol(Test2, Decl(strictNullNotNullIndexTypeNoLib.ts, 24, 1)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 12)) +>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50)) + + attrs: Readonly; +>attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26)) +>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0)) +>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 12)) + + m() { +>m : Symbol(Test2.m, Decl(strictNullNotNullIndexTypeNoLib.ts, 27, 23)) + + return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally +>this.attrs.params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) +>this.attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26)) +>this : Symbol(Test2, Decl(strictNullNotNullIndexTypeNoLib.ts, 24, 1)) +>attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26)) +>params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) + } +} diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types new file mode 100644 index 0000000000000..1d65131c1148e --- /dev/null +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types @@ -0,0 +1,97 @@ +=== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts === +type Readonly = {readonly [K in keyof T]: T[K]} +>Readonly : Readonly +>T : T +>K : K +>T : T +>T : T +>K : K + +interface A { +>A : A + + params?: { name: string; }; +>params : { name: string; } | undefined +>name : string +} + +class Test { +>Test : Test +>T : T +>A : A + + attrs: Readonly; +>attrs : Readonly +>Readonly : Readonly +>T : T + + m() { +>m : () => void + + this.attrs.params!.name; +>this.attrs.params!.name : string +>this.attrs.params! : T["params"] extends null | undefined ? never : T["params"] +>this.attrs.params : T["params"] +>this.attrs : Readonly +>this : this +>attrs : Readonly +>params : T["params"] +>name : string + } +} + +interface Foo { +>Foo : Foo + + foo?: number; +>foo : number | undefined +} + +class FooClass

{ +>FooClass : FooClass

+>P : P +>Foo : Foo +>Foo : Foo + + properties: Readonly

; +>properties : Readonly

+>Readonly : Readonly +>P : P + + foo(): number { +>foo : () => number + + const { foo = 42 } = this.properties; +>foo : number +>42 : 42 +>this.properties : Readonly

+>this : this +>properties : Readonly

+ + return foo; +>foo : number + } +} + +class Test2 { +>Test2 : Test2 +>T : T +>A : A + + attrs: Readonly; +>attrs : Readonly +>Readonly : Readonly +>T : T + + m() { +>m : () => T["params"] extends null | undefined ? never : T["params"] + + return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally +>this.attrs.params! : T["params"] extends null | undefined ? never : T["params"] +>this.attrs.params : T["params"] +>this.attrs : Readonly +>this : this +>attrs : Readonly +>params : T["params"] + } +} diff --git a/tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts b/tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts new file mode 100644 index 0000000000000..f5df0e2be8b72 --- /dev/null +++ b/tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts @@ -0,0 +1,35 @@ +// @strictNullChecks: true +// @noLib: true +type Readonly = {readonly [K in keyof T]: T[K]} +interface A { + params?: { name: string; }; +} + +class Test { + attrs: Readonly; + + m() { + this.attrs.params!.name; + } +} + +interface Foo { + foo?: number; +} + +class FooClass

{ + properties: Readonly

; + + foo(): number { + const { foo = 42 } = this.properties; + return foo; + } +} + +class Test2 { + attrs: Readonly; + + m() { + return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally + } +} \ No newline at end of file From 2a9243795176e232888afa065624e8d5f0caa5dd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 5 Mar 2018 13:42:55 -0800 Subject: [PATCH 3/3] Remove conditional type fallback for when lib is not present --- src/compiler/checker.ts | 17 +---------------- .../strictNullNotNullIndexTypeNoLib.errors.txt | 5 ++++- .../strictNullNotNullIndexTypeNoLib.symbols | 2 -- .../strictNullNotNullIndexTypeNoLib.types | 10 +++++----- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 357b87b6151a5..54db1ba5e9aae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -401,9 +401,6 @@ namespace ts { let autoArrayType: Type; let anyReadonlyArrayType: Type; let deferredGlobalNonNullableTypeAlias: Symbol; - let deferredGlobalNonNullableTypeFallback: Type; - let deferredGlobalNonNullableTypeFallbackInstantiationCache: Map; - let deferredGlobalNonNullableTypeParameterFallback: TypeParameter; // The library files are only loaded when the feature is used. // This allows users to just specify library files they want to used through --lib @@ -11049,19 +11046,7 @@ namespace ts { if (deferredGlobalNonNullableTypeAlias !== unknownSymbol) { return getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]); } - if (!deferredGlobalNonNullableTypeFallback) { - const p = deferredGlobalNonNullableTypeParameterFallback = createType(TypeFlags.TypeParameter) as TypeParameter; - deferredGlobalNonNullableTypeFallback = getConditionalType(p, getUnionType([nullType, undefinedType]), neverType, p, /*inferTypeParameters*/ undefined, /*target*/ undefined, /*mapper*/ undefined, /*alias*/ undefined, /*aliasTypeArguments*/ undefined); - deferredGlobalNonNullableTypeFallbackInstantiationCache = createMap(); - } - // Fallback to manufacturing an anonymous conditional type instantiation - const args = [type]; - const id = getTypeListId(args); - let instantiation = deferredGlobalNonNullableTypeFallbackInstantiationCache.get(id); - if (!instantiation) { - deferredGlobalNonNullableTypeFallbackInstantiationCache.set(id, instantiation = instantiateType(deferredGlobalNonNullableTypeFallback, createTypeMapper([deferredGlobalNonNullableTypeParameterFallback], [type]))); - } - return instantiation; + return getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); // Type alias unavailable, fall back to non-higherorder behavior } function getNonNullableType(type: Type): Type { diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt index 9f4651b07c3fb..59e104ecd5ceb 100644 --- a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.errors.txt @@ -6,6 +6,7 @@ error TS2318: Cannot find global type 'Number'. error TS2318: Cannot find global type 'Object'. error TS2318: Cannot find global type 'RegExp'. error TS2318: Cannot find global type 'String'. +tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts(10,28): error TS2339: Property 'name' does not exist on type 'T["params"]'. !!! error TS2318: Cannot find global type 'Array'. @@ -16,7 +17,7 @@ error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'Object'. !!! error TS2318: Cannot find global type 'RegExp'. !!! error TS2318: Cannot find global type 'String'. -==== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts (0 errors) ==== +==== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts (1 errors) ==== type Readonly = {readonly [K in keyof T]: T[K]} interface A { params?: { name: string; }; @@ -27,6 +28,8 @@ error TS2318: Cannot find global type 'String'. m() { this.attrs.params!.name; + ~~~~ +!!! error TS2339: Property 'name' does not exist on type 'T["params"]'. } } diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols index a41798f2f521b..04e7779df1329 100644 --- a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.symbols @@ -29,13 +29,11 @@ class Test { >m : Symbol(Test.m, Decl(strictNullNotNullIndexTypeNoLib.ts, 6, 23)) this.attrs.params!.name; ->this.attrs.params!.name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14)) >this.attrs.params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) >this.attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25)) >this : Symbol(Test, Decl(strictNullNotNullIndexTypeNoLib.ts, 3, 1)) >attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25)) >params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13)) ->name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14)) } } diff --git a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types index 1d65131c1148e..4f351dfe044fd 100644 --- a/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types +++ b/tests/baselines/reference/strictNullNotNullIndexTypeNoLib.types @@ -29,14 +29,14 @@ class Test { >m : () => void this.attrs.params!.name; ->this.attrs.params!.name : string ->this.attrs.params! : T["params"] extends null | undefined ? never : T["params"] +>this.attrs.params!.name : any +>this.attrs.params! : T["params"] >this.attrs.params : T["params"] >this.attrs : Readonly >this : this >attrs : Readonly >params : T["params"] ->name : string +>name : any } } @@ -84,10 +84,10 @@ class Test2 { >T : T m() { ->m : () => T["params"] extends null | undefined ? never : T["params"] +>m : () => T["params"] return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally ->this.attrs.params! : T["params"] extends null | undefined ? never : T["params"] +>this.attrs.params! : T["params"] >this.attrs.params : T["params"] >this.attrs : Readonly >this : this