From 5966b1edaf98567a1a5c3db6b8f4d82aae62989a Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 26 Oct 2022 16:50:29 -0700 Subject: [PATCH 1/4] Add test --- .../baselines/reference/issue35004.errors.txt | 35 +++++++++ tests/baselines/reference/issue35004.js | 71 +++++++++++++++++++ tests/baselines/reference/issue35004.symbols | 58 +++++++++++++++ tests/baselines/reference/issue35004.types | 65 +++++++++++++++++ tests/cases/compiler/issue35004.ts | 28 ++++++++ 5 files changed, 257 insertions(+) create mode 100644 tests/baselines/reference/issue35004.errors.txt create mode 100644 tests/baselines/reference/issue35004.js create mode 100644 tests/baselines/reference/issue35004.symbols create mode 100644 tests/baselines/reference/issue35004.types create mode 100644 tests/cases/compiler/issue35004.ts diff --git a/tests/baselines/reference/issue35004.errors.txt b/tests/baselines/reference/issue35004.errors.txt new file mode 100644 index 0000000000000..e88441198f9c1 --- /dev/null +++ b/tests/baselines/reference/issue35004.errors.txt @@ -0,0 +1,35 @@ +tests/cases/compiler/src/core/foo.ts(4,1): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. +tests/cases/compiler/src/other/bar.ts(4,1): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. + + +==== tests/cases/compiler/src/core/_namespaces/ts.ts (0 errors) ==== + import * as Debug from "../debug"; + export { Debug }; + +==== tests/cases/compiler/src/core/debug.ts (0 errors) ==== + export declare function assert(expression: unknown): asserts expression; + + +==== tests/cases/compiler/src/core/foo.ts (1 errors) ==== + import * as ts from "./_namespaces/ts"; + import { Debug } from "./_namespaces/ts"; + + ts.Debug.assert(true); + ~~~~~~~~~~~~~~~ +!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. + Debug.assert(true); + + +==== tests/cases/compiler/src/other/_namespaces/ts.ts (0 errors) ==== + export * from "../../core/_namespaces/ts" + + +==== tests/cases/compiler/src/other/bar.ts (1 errors) ==== + import * as ts from "./_namespaces/ts"; + import { Debug } from "./_namespaces/ts"; + + ts.Debug.assert(true); + ~~~~~~~~~~~~~~~ +!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. + Debug.assert(true); + \ No newline at end of file diff --git a/tests/baselines/reference/issue35004.js b/tests/baselines/reference/issue35004.js new file mode 100644 index 0000000000000..ad8e3108ed88f --- /dev/null +++ b/tests/baselines/reference/issue35004.js @@ -0,0 +1,71 @@ +//// [tests/cases/compiler/issue35004.ts] //// + +//// [ts.ts] +import * as Debug from "../debug"; +export { Debug }; + +//// [debug.ts] +export declare function assert(expression: unknown): asserts expression; + + +//// [foo.ts] +import * as ts from "./_namespaces/ts"; +import { Debug } from "./_namespaces/ts"; + +ts.Debug.assert(true); +Debug.assert(true); + + +//// [ts.ts] +export * from "../../core/_namespaces/ts" + + +//// [bar.ts] +import * as ts from "./_namespaces/ts"; +import { Debug } from "./_namespaces/ts"; + +ts.Debug.assert(true); +Debug.assert(true); + + +//// [debug.js] +"use strict"; +exports.__esModule = true; +//// [ts.js] +"use strict"; +exports.__esModule = true; +exports.Debug = void 0; +var Debug = require("../debug"); +exports.Debug = Debug; +//// [foo.js] +"use strict"; +exports.__esModule = true; +var ts = require("./_namespaces/ts"); +var ts_1 = require("./_namespaces/ts"); +ts.Debug.assert(true); +ts_1.Debug.assert(true); +//// [ts.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +exports.__esModule = true; +__exportStar(require("../../core/_namespaces/ts"), exports); +//// [bar.js] +"use strict"; +exports.__esModule = true; +var ts = require("./_namespaces/ts"); +var ts_1 = require("./_namespaces/ts"); +ts.Debug.assert(true); +ts_1.Debug.assert(true); diff --git a/tests/baselines/reference/issue35004.symbols b/tests/baselines/reference/issue35004.symbols new file mode 100644 index 0000000000000..ea4fa4af61712 --- /dev/null +++ b/tests/baselines/reference/issue35004.symbols @@ -0,0 +1,58 @@ +=== tests/cases/compiler/src/core/_namespaces/ts.ts === +import * as Debug from "../debug"; +>Debug : Symbol(Debug, Decl(ts.ts, 0, 6)) + +export { Debug }; +>Debug : Symbol(Debug, Decl(ts.ts, 1, 8)) + +=== tests/cases/compiler/src/core/debug.ts === +export declare function assert(expression: unknown): asserts expression; +>assert : Symbol(assert, Decl(debug.ts, 0, 0)) +>expression : Symbol(expression, Decl(debug.ts, 0, 31)) +>expression : Symbol(expression, Decl(debug.ts, 0, 31)) + + +=== tests/cases/compiler/src/core/foo.ts === +import * as ts from "./_namespaces/ts"; +>ts : Symbol(ts, Decl(foo.ts, 0, 6)) + +import { Debug } from "./_namespaces/ts"; +>Debug : Symbol(Debug, Decl(foo.ts, 1, 8)) + +ts.Debug.assert(true); +>ts.Debug.assert : Symbol(ts.Debug.assert, Decl(debug.ts, 0, 0)) +>ts.Debug : Symbol(ts.Debug, Decl(ts.ts, 1, 8)) +>ts : Symbol(ts, Decl(foo.ts, 0, 6)) +>Debug : Symbol(ts.Debug, Decl(ts.ts, 1, 8)) +>assert : Symbol(ts.Debug.assert, Decl(debug.ts, 0, 0)) + +Debug.assert(true); +>Debug.assert : Symbol(ts.Debug.assert, Decl(debug.ts, 0, 0)) +>Debug : Symbol(Debug, Decl(foo.ts, 1, 8)) +>assert : Symbol(ts.Debug.assert, Decl(debug.ts, 0, 0)) + + +=== tests/cases/compiler/src/other/_namespaces/ts.ts === + +export * from "../../core/_namespaces/ts" + + +=== tests/cases/compiler/src/other/bar.ts === +import * as ts from "./_namespaces/ts"; +>ts : Symbol(ts, Decl(bar.ts, 0, 6)) + +import { Debug } from "./_namespaces/ts"; +>Debug : Symbol(Debug, Decl(bar.ts, 1, 8)) + +ts.Debug.assert(true); +>ts.Debug.assert : Symbol(Debug.assert, Decl(debug.ts, 0, 0)) +>ts.Debug : Symbol(ts.Debug, Decl(ts.ts, 1, 8)) +>ts : Symbol(ts, Decl(bar.ts, 0, 6)) +>Debug : Symbol(ts.Debug, Decl(ts.ts, 1, 8)) +>assert : Symbol(Debug.assert, Decl(debug.ts, 0, 0)) + +Debug.assert(true); +>Debug.assert : Symbol(Debug.assert, Decl(debug.ts, 0, 0)) +>Debug : Symbol(Debug, Decl(bar.ts, 1, 8)) +>assert : Symbol(Debug.assert, Decl(debug.ts, 0, 0)) + diff --git a/tests/baselines/reference/issue35004.types b/tests/baselines/reference/issue35004.types new file mode 100644 index 0000000000000..82610d9ca68e8 --- /dev/null +++ b/tests/baselines/reference/issue35004.types @@ -0,0 +1,65 @@ +=== tests/cases/compiler/src/core/_namespaces/ts.ts === +import * as Debug from "../debug"; +>Debug : typeof Debug + +export { Debug }; +>Debug : typeof Debug + +=== tests/cases/compiler/src/core/debug.ts === +export declare function assert(expression: unknown): asserts expression; +>assert : (expression: unknown) => asserts expression +>expression : unknown + + +=== tests/cases/compiler/src/core/foo.ts === +import * as ts from "./_namespaces/ts"; +>ts : typeof ts + +import { Debug } from "./_namespaces/ts"; +>Debug : typeof ts.Debug + +ts.Debug.assert(true); +>ts.Debug.assert(true) : void +>ts.Debug.assert : (expression: unknown) => asserts expression +>ts.Debug : typeof ts.Debug +>ts : typeof ts +>Debug : typeof ts.Debug +>assert : (expression: unknown) => asserts expression +>true : true + +Debug.assert(true); +>Debug.assert(true) : void +>Debug.assert : (expression: unknown) => asserts expression +>Debug : typeof ts.Debug +>assert : (expression: unknown) => asserts expression +>true : true + + +=== tests/cases/compiler/src/other/_namespaces/ts.ts === + +export * from "../../core/_namespaces/ts" + + +=== tests/cases/compiler/src/other/bar.ts === +import * as ts from "./_namespaces/ts"; +>ts : typeof ts + +import { Debug } from "./_namespaces/ts"; +>Debug : typeof ts.Debug + +ts.Debug.assert(true); +>ts.Debug.assert(true) : void +>ts.Debug.assert : (expression: unknown) => asserts expression +>ts.Debug : typeof ts.Debug +>ts : typeof ts +>Debug : typeof ts.Debug +>assert : (expression: unknown) => asserts expression +>true : true + +Debug.assert(true); +>Debug.assert(true) : void +>Debug.assert : (expression: unknown) => asserts expression +>Debug : typeof ts.Debug +>assert : (expression: unknown) => asserts expression +>true : true + diff --git a/tests/cases/compiler/issue35004.ts b/tests/cases/compiler/issue35004.ts new file mode 100644 index 0000000000000..93d912ad1152c --- /dev/null +++ b/tests/cases/compiler/issue35004.ts @@ -0,0 +1,28 @@ +// @strict: true + +// @filename: src/core/_namespaces/ts.ts +import * as Debug from "../debug"; +export { Debug }; + +// @filename: src/core/debug.ts +export declare function assert(expression: unknown): asserts expression; + + +// @filename: src/core/foo.ts +import * as ts from "./_namespaces/ts"; +import { Debug } from "./_namespaces/ts"; + +ts.Debug.assert(true); +Debug.assert(true); + + +// @filename: src/other/_namespaces/ts.ts +export * from "../../core/_namespaces/ts" + + +// @filename: src/other/bar.ts +import * as ts from "./_namespaces/ts"; +import { Debug } from "./_namespaces/ts"; + +ts.Debug.assert(true); +Debug.assert(true); From feece9c2d38a51a102fc4335ec8e6314e11bf003 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:05:20 -0700 Subject: [PATCH 2/4] Resolve alias of property in getTypeOfDottedName --- src/compiler/checker.ts | 2 +- .../baselines/reference/issue35004.errors.txt | 35 ------------------- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 tests/baselines/reference/issue35004.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2a03341ea6de1..07d1c27c632bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24548,7 +24548,7 @@ namespace ts { else { prop = getPropertyOfType(type, name.escapedText); } - return prop && getExplicitTypeOfSymbol(prop, diagnostic); + return prop && getExplicitTypeOfSymbol(prop.flags & SymbolFlags.Alias ? resolveAlias(prop) : prop, diagnostic); } return undefined; } diff --git a/tests/baselines/reference/issue35004.errors.txt b/tests/baselines/reference/issue35004.errors.txt deleted file mode 100644 index e88441198f9c1..0000000000000 --- a/tests/baselines/reference/issue35004.errors.txt +++ /dev/null @@ -1,35 +0,0 @@ -tests/cases/compiler/src/core/foo.ts(4,1): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. -tests/cases/compiler/src/other/bar.ts(4,1): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. - - -==== tests/cases/compiler/src/core/_namespaces/ts.ts (0 errors) ==== - import * as Debug from "../debug"; - export { Debug }; - -==== tests/cases/compiler/src/core/debug.ts (0 errors) ==== - export declare function assert(expression: unknown): asserts expression; - - -==== tests/cases/compiler/src/core/foo.ts (1 errors) ==== - import * as ts from "./_namespaces/ts"; - import { Debug } from "./_namespaces/ts"; - - ts.Debug.assert(true); - ~~~~~~~~~~~~~~~ -!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. - Debug.assert(true); - - -==== tests/cases/compiler/src/other/_namespaces/ts.ts (0 errors) ==== - export * from "../../core/_namespaces/ts" - - -==== tests/cases/compiler/src/other/bar.ts (1 errors) ==== - import * as ts from "./_namespaces/ts"; - import { Debug } from "./_namespaces/ts"; - - ts.Debug.assert(true); - ~~~~~~~~~~~~~~~ -!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation. - Debug.assert(true); - \ No newline at end of file From bb7555200b24e3ee003c63790f5a90a28a9576db Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:08:38 -0700 Subject: [PATCH 3/4] Always resolve --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07d1c27c632bb..c4a19cb8e8c2d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24490,6 +24490,7 @@ namespace ts { } function getExplicitTypeOfSymbol(symbol: Symbol, diagnostic?: Diagnostic) { + symbol = resolveSymbol(symbol); if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.ValueModule)) { return getTypeOfSymbol(symbol); } @@ -24529,7 +24530,7 @@ namespace ts { switch (node.kind) { case SyntaxKind.Identifier: const symbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(node as Identifier)); - return getExplicitTypeOfSymbol(symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol, diagnostic); + return getExplicitTypeOfSymbol(symbol, diagnostic); case SyntaxKind.ThisKeyword: return getExplicitThisType(node); case SyntaxKind.SuperKeyword: @@ -24548,7 +24549,7 @@ namespace ts { else { prop = getPropertyOfType(type, name.escapedText); } - return prop && getExplicitTypeOfSymbol(prop.flags & SymbolFlags.Alias ? resolveAlias(prop) : prop, diagnostic); + return prop && getExplicitTypeOfSymbol(prop, diagnostic); } return undefined; } From d5be4375d11476f6a43a2f5cc80a24f784cb80c3 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:26:48 -0700 Subject: [PATCH 4/4] Update tests --- ...js => assertionFunctionWildcardImport1.js} | 2 +- ... assertionFunctionWildcardImport1.symbols} | 0 ...=> assertionFunctionWildcardImport1.types} | 0 .../assertionFunctionWildcardImport2.js | 40 +++++++++++++++ .../assertionFunctionWildcardImport2.symbols | 46 +++++++++++++++++ .../assertionFunctionWildcardImport2.types | 50 +++++++++++++++++++ ...ts => assertionFunctionWildcardImport1.ts} | 0 .../assertionFunctionWildcardImport2.ts | 20 ++++++++ 8 files changed, 157 insertions(+), 1 deletion(-) rename tests/baselines/reference/{issue35004.js => assertionFunctionWildcardImport1.js} (93%) rename tests/baselines/reference/{issue35004.symbols => assertionFunctionWildcardImport1.symbols} (100%) rename tests/baselines/reference/{issue35004.types => assertionFunctionWildcardImport1.types} (100%) create mode 100644 tests/baselines/reference/assertionFunctionWildcardImport2.js create mode 100644 tests/baselines/reference/assertionFunctionWildcardImport2.symbols create mode 100644 tests/baselines/reference/assertionFunctionWildcardImport2.types rename tests/cases/compiler/{issue35004.ts => assertionFunctionWildcardImport1.ts} (100%) create mode 100644 tests/cases/compiler/assertionFunctionWildcardImport2.ts diff --git a/tests/baselines/reference/issue35004.js b/tests/baselines/reference/assertionFunctionWildcardImport1.js similarity index 93% rename from tests/baselines/reference/issue35004.js rename to tests/baselines/reference/assertionFunctionWildcardImport1.js index ad8e3108ed88f..618e433f9d500 100644 --- a/tests/baselines/reference/issue35004.js +++ b/tests/baselines/reference/assertionFunctionWildcardImport1.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/issue35004.ts] //// +//// [tests/cases/compiler/assertionFunctionWildcardImport1.ts] //// //// [ts.ts] import * as Debug from "../debug"; diff --git a/tests/baselines/reference/issue35004.symbols b/tests/baselines/reference/assertionFunctionWildcardImport1.symbols similarity index 100% rename from tests/baselines/reference/issue35004.symbols rename to tests/baselines/reference/assertionFunctionWildcardImport1.symbols diff --git a/tests/baselines/reference/issue35004.types b/tests/baselines/reference/assertionFunctionWildcardImport1.types similarity index 100% rename from tests/baselines/reference/issue35004.types rename to tests/baselines/reference/assertionFunctionWildcardImport1.types diff --git a/tests/baselines/reference/assertionFunctionWildcardImport2.js b/tests/baselines/reference/assertionFunctionWildcardImport2.js new file mode 100644 index 0000000000000..a56f26f60f975 --- /dev/null +++ b/tests/baselines/reference/assertionFunctionWildcardImport2.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/assertionFunctionWildcardImport2.ts] //// + +//// [asserts.ts] +function isNonNullable(obj: T): asserts obj is NonNullable { + if (obj === undefined || obj === null) { + throw new Error("Must not be a nullable value"); + } +} + +export { + isNonNullable +}; + +//// [test.ts] +import * as asserts from "./asserts"; + +function test(obj: string | null): void { + asserts.isNonNullable(obj); + obj.trim(); +} + + +//// [asserts.js] +"use strict"; +exports.__esModule = true; +exports.isNonNullable = void 0; +function isNonNullable(obj) { + if (obj === undefined || obj === null) { + throw new Error("Must not be a nullable value"); + } +} +exports.isNonNullable = isNonNullable; +//// [test.js] +"use strict"; +exports.__esModule = true; +var asserts = require("./asserts"); +function test(obj) { + asserts.isNonNullable(obj); + obj.trim(); +} diff --git a/tests/baselines/reference/assertionFunctionWildcardImport2.symbols b/tests/baselines/reference/assertionFunctionWildcardImport2.symbols new file mode 100644 index 0000000000000..ca06e3db686d9 --- /dev/null +++ b/tests/baselines/reference/assertionFunctionWildcardImport2.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/asserts.ts === +function isNonNullable(obj: T): asserts obj is NonNullable { +>isNonNullable : Symbol(isNonNullable, Decl(asserts.ts, 0, 0)) +>T : Symbol(T, Decl(asserts.ts, 0, 23)) +>obj : Symbol(obj, Decl(asserts.ts, 0, 26)) +>T : Symbol(T, Decl(asserts.ts, 0, 23)) +>obj : Symbol(obj, Decl(asserts.ts, 0, 26)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(asserts.ts, 0, 23)) + + if (obj === undefined || obj === null) { +>obj : Symbol(obj, Decl(asserts.ts, 0, 26)) +>undefined : Symbol(undefined) +>obj : Symbol(obj, Decl(asserts.ts, 0, 26)) + + throw new Error("Must not be a nullable value"); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } +} + +export { + isNonNullable +>isNonNullable : Symbol(isNonNullable, Decl(asserts.ts, 6, 8)) + +}; + +=== tests/cases/compiler/test.ts === +import * as asserts from "./asserts"; +>asserts : Symbol(asserts, Decl(test.ts, 0, 6)) + +function test(obj: string | null): void { +>test : Symbol(test, Decl(test.ts, 0, 37)) +>obj : Symbol(obj, Decl(test.ts, 2, 14)) + + asserts.isNonNullable(obj); +>asserts.isNonNullable : Symbol(asserts.isNonNullable, Decl(asserts.ts, 6, 8)) +>asserts : Symbol(asserts, Decl(test.ts, 0, 6)) +>isNonNullable : Symbol(asserts.isNonNullable, Decl(asserts.ts, 6, 8)) +>obj : Symbol(obj, Decl(test.ts, 2, 14)) + + obj.trim(); +>obj.trim : Symbol(String.trim, Decl(lib.es5.d.ts, --, --)) +>obj : Symbol(obj, Decl(test.ts, 2, 14)) +>trim : Symbol(String.trim, Decl(lib.es5.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/assertionFunctionWildcardImport2.types b/tests/baselines/reference/assertionFunctionWildcardImport2.types new file mode 100644 index 0000000000000..ffceb8e919855 --- /dev/null +++ b/tests/baselines/reference/assertionFunctionWildcardImport2.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/asserts.ts === +function isNonNullable(obj: T): asserts obj is NonNullable { +>isNonNullable : (obj: T) => asserts obj is NonNullable +>obj : T + + if (obj === undefined || obj === null) { +>obj === undefined || obj === null : boolean +>obj === undefined : boolean +>obj : T +>undefined : undefined +>obj === null : boolean +>obj : T & ({} | null) +>null : null + + throw new Error("Must not be a nullable value"); +>new Error("Must not be a nullable value") : Error +>Error : ErrorConstructor +>"Must not be a nullable value" : "Must not be a nullable value" + } +} + +export { + isNonNullable +>isNonNullable : (obj: T) => asserts obj is NonNullable + +}; + +=== tests/cases/compiler/test.ts === +import * as asserts from "./asserts"; +>asserts : typeof asserts + +function test(obj: string | null): void { +>test : (obj: string | null) => void +>obj : string | null +>null : null + + asserts.isNonNullable(obj); +>asserts.isNonNullable(obj) : void +>asserts.isNonNullable : (obj: T) => asserts obj is NonNullable +>asserts : typeof asserts +>isNonNullable : (obj: T) => asserts obj is NonNullable +>obj : string | null + + obj.trim(); +>obj.trim() : string +>obj.trim : () => string +>obj : string +>trim : () => string +} + diff --git a/tests/cases/compiler/issue35004.ts b/tests/cases/compiler/assertionFunctionWildcardImport1.ts similarity index 100% rename from tests/cases/compiler/issue35004.ts rename to tests/cases/compiler/assertionFunctionWildcardImport1.ts diff --git a/tests/cases/compiler/assertionFunctionWildcardImport2.ts b/tests/cases/compiler/assertionFunctionWildcardImport2.ts new file mode 100644 index 0000000000000..3fe0c10d03f3e --- /dev/null +++ b/tests/cases/compiler/assertionFunctionWildcardImport2.ts @@ -0,0 +1,20 @@ +// @strict: true + +// @filename: asserts.ts +function isNonNullable(obj: T): asserts obj is NonNullable { + if (obj === undefined || obj === null) { + throw new Error("Must not be a nullable value"); + } +} + +export { + isNonNullable +}; + +// @filename: test.ts +import * as asserts from "./asserts"; + +function test(obj: string | null): void { + asserts.isNonNullable(obj); + obj.trim(); +}