From 6121ff28719b2f0f9b54ef2537acd2072828c3a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:06:38 +0000 Subject: [PATCH 1/6] Initial plan From 24718b5f1eac6e127fa49d9fc50ba26c75987f10 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:25:05 +0000 Subject: [PATCH 2/6] Add symbol name to TS2742 error when available from symbolToTypeNode Co-authored-by: arcanis <1037931+arcanis@users.noreply.github.com> --- src/compiler/checker.ts | 10 +++---- src/compiler/diagnosticMessages.json | 6 +++- src/compiler/transformers/declarations.ts | 9 ++++-- src/compiler/types.ts | 2 +- ...mitCommonJsModuleReferencedType.errors.txt | 4 +-- ...EmitObjectAssignedDefaultExport.errors.txt | 4 +-- ...EmitReexportedSymlinkReference3.errors.txt | 4 +-- ...ationEmitUnsafeImportSymbolName.errors.txt | 16 ++++++++++ .../declarationEmitUnsafeImportSymbolName.js | 20 +++++++++++++ ...larationEmitUnsafeImportSymbolName.symbols | 25 ++++++++++++++++ ...eclarationEmitUnsafeImportSymbolName.types | 30 +++++++++++++++++++ .../declarationEmitUsingTypeAlias1.errors.txt | 8 ++--- ...tsSpecifierGenerationConditions.errors.txt | 4 +-- ...cifierResolution(module=node16).errors.txt | 4 +-- ...cifierResolution(module=node18).errors.txt | 4 +-- ...cifierResolution(module=node20).errors.txt | 4 +-- ...fierResolution(module=nodenext).errors.txt | 4 +-- ...sExportsSourceTs(module=node16).errors.txt | 4 +-- ...sExportsSourceTs(module=node18).errors.txt | 4 +-- ...sExportsSourceTs(module=node20).errors.txt | 4 +-- ...xportsSourceTs(module=nodenext).errors.txt | 4 +-- ...rough-indirect-symlink-moduleCaseChange.js | 2 +- ...ibling-package-through-indirect-symlink.js | 2 +- .../declarationEmitUnsafeImportSymbolName.ts | 13 ++++++++ 24 files changed, 152 insertions(+), 39 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt create mode 100644 tests/baselines/reference/declarationEmitUnsafeImportSymbolName.js create mode 100644 tests/baselines/reference/declarationEmitUnsafeImportSymbolName.symbols create mode 100644 tests/baselines/reference/declarationEmitUnsafeImportSymbolName.types create mode 100644 tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8fa3c4fce2a4a..97bb6ae0d94ee 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8090,8 +8090,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { reportInaccessibleUniqueSymbolError() { markError(() => oldTracker.reportInaccessibleUniqueSymbolError()); }, - reportLikelyUnsafeImportRequiredError(specifier) { - markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier)); + reportLikelyUnsafeImportRequiredError(specifier, symbolName) { + markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier, symbolName)); }, reportNonSerializableProperty(name) { markError(() => oldTracker.reportNonSerializableProperty(name)); @@ -8717,7 +8717,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // since declaration files with these kinds of references are liable to fail when published :( context.encounteredError = true; if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier); + context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, chain.length > 1 ? unescapeLeadingUnderscores(symbol.escapedName) : undefined); } } } @@ -54370,10 +54370,10 @@ class SymbolTrackerImpl implements SymbolTracker { } } - reportLikelyUnsafeImportRequiredError(specifier: string): void { + reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string): void { if (this.inner?.reportLikelyUnsafeImportRequiredError) { this.onDiagnosticReported(); - this.inner.reportLikelyUnsafeImportRequiredError(specifier); + this.inner.reportLikelyUnsafeImportRequiredError(specifier, symbolName); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 166ee5f135ace..0247c9ea5807e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4022,8 +4022,12 @@ "category": "Error", "code": 2882 }, + "The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary. The type originates from symbol '{2}'.": { + "category": "Error", + "code": 2883 + }, - "Import declaration '{0}' is using private name '{1}'.": { + "Import declaration '{0}' is using private name '{1}'.":{ "category": "Error", "code": 4000 }, diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 0867afa56ec1a..3b3deb31d5b72 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -408,9 +408,14 @@ export function transformDeclarations(context: TransformationContext): Transform } } - function reportLikelyUnsafeImportRequiredError(specifier: string) { + function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier)); + if (symbolName) { + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary_The_type_originates_from_symbol_2, errorDeclarationNameWithFallback(), specifier, symbolName)); + } + else { + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier)); + } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 08c3b16898307..9291b037dbb3c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -10050,7 +10050,7 @@ export interface SymbolTracker { reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; reportCyclicStructureError?(): void; - reportLikelyUnsafeImportRequiredError?(specifier: string): void; + reportLikelyUnsafeImportRequiredError?(specifier: string, symbolName?: string): void; reportTruncationError?(): void; moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string; }; reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void; diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt index 5b208e8259a06..79feb64c90436 100644 --- a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt @@ -1,4 +1,4 @@ -r/entry.ts(3,14): error TS2742: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NestedProps'. ==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -23,6 +23,6 @@ r/entry.ts(3,14): error TS2742: The inferred type of 'x' cannot be named without import { bar } from "root"; export const x = foo(); ~ -!!! error TS2742: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NestedProps'. export const y = bar(); \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt index 1971f0d340ccf..3cfebea5198e0 100644 --- a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt +++ b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt @@ -1,4 +1,4 @@ -index.ts(7,1): error TS2742: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. +index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NonReactStatics'. ==== node_modules/styled-components/node_modules/hoist-non-react-statics/index.d.ts (0 errors) ==== @@ -43,5 +43,5 @@ index.ts(7,1): error TS2742: The inferred type of 'default' cannot be named with ~~~~~ }); ~~~ -!!! error TS2742: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NonReactStatics'. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt index be730da192ed9..a7aa4fe947330 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -1,4 +1,4 @@ -monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. ==== monorepo/pkg3/tsconfig.json (0 errors) ==== @@ -21,7 +21,7 @@ monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cann export const ADMIN = MetadataAccessor.create('1'); ~~~~~ -!!! error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. ==== monorepo/pkg1/dist/index.d.ts (0 errors) ==== export * from './types'; ==== monorepo/pkg1/dist/types.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt new file mode 100644 index 0000000000000..0b284f10602c6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt @@ -0,0 +1,16 @@ +r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'MySpecialType'. + + +==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== + export interface MySpecialType { + val: string; + } +==== r/node_modules/foo/index.d.ts (0 errors) ==== + import { MySpecialType } from "nested"; + export function getSpecial(): MySpecialType; +==== r/entry.ts (1 errors) ==== + import { getSpecial } from "foo"; + export const special = getSpecial(); + ~~~~~~~ +!!! error TS2883: The inferred type of 'special' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'MySpecialType'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.js b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.js new file mode 100644 index 0000000000000..cc27f9018b498 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts] //// + +//// [index.d.ts] +export interface MySpecialType { + val: string; +} +//// [index.d.ts] +import { MySpecialType } from "nested"; +export function getSpecial(): MySpecialType; +//// [entry.ts] +import { getSpecial } from "foo"; +export const special = getSpecial(); + + +//// [entry.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.special = void 0; +const foo_1 = require("foo"); +exports.special = (0, foo_1.getSpecial)(); diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.symbols b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.symbols new file mode 100644 index 0000000000000..ae266c8feddac --- /dev/null +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.symbols @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts] //// + +=== r/node_modules/foo/node_modules/nested/index.d.ts === +export interface MySpecialType { +>MySpecialType : Symbol(MySpecialType, Decl(index.d.ts, 0, 0)) + + val: string; +>val : Symbol(MySpecialType.val, Decl(index.d.ts, 0, 32)) +} +=== r/node_modules/foo/index.d.ts === +import { MySpecialType } from "nested"; +>MySpecialType : Symbol(MySpecialType, Decl(index.d.ts, 0, 8)) + +export function getSpecial(): MySpecialType; +>getSpecial : Symbol(getSpecial, Decl(index.d.ts, 0, 39)) +>MySpecialType : Symbol(MySpecialType, Decl(index.d.ts, 0, 8)) + +=== r/entry.ts === +import { getSpecial } from "foo"; +>getSpecial : Symbol(getSpecial, Decl(entry.ts, 0, 8)) + +export const special = getSpecial(); +>special : Symbol(special, Decl(entry.ts, 1, 12)) +>getSpecial : Symbol(getSpecial, Decl(entry.ts, 0, 8)) + diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.types b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.types new file mode 100644 index 0000000000000..65414f47bd1d6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.types @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts] //// + +=== r/node_modules/foo/node_modules/nested/index.d.ts === +export interface MySpecialType { + val: string; +>val : string +> : ^^^^^^ +} +=== r/node_modules/foo/index.d.ts === +import { MySpecialType } from "nested"; +>MySpecialType : any +> : ^^^ + +export function getSpecial(): MySpecialType; +>getSpecial : () => MySpecialType +> : ^^^^^^ + +=== r/entry.ts === +import { getSpecial } from "foo"; +>getSpecial : () => import("foo/node_modules/nested").MySpecialType +> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ + +export const special = getSpecial(); +>special : import("foo/node_modules/nested").MySpecialType +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>getSpecial() : import("foo/node_modules/nested").MySpecialType +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>getSpecial : () => import("foo/node_modules/nested").MySpecialType +> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt index c31e66a237a62..a10062767f3b1 100644 --- a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt +++ b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt @@ -1,5 +1,5 @@ -src/index.ts(3,14): error TS2742: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. -src/index.ts(7,14): error TS2742: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +src/index.ts(3,14): error TS2883: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'SomeType'. +src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Other'. ==== node_modules/some-dep/dist/inner.d.ts (0 errors) ==== @@ -23,12 +23,12 @@ src/index.ts(7,14): error TS2742: The inferred type of 'bar' cannot be named wit export const foo = (thing: SomeType) => { ~~~ -!!! error TS2742: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'SomeType'. return thing; }; export const bar = (thing: SomeType) => { ~~~ -!!! error TS2742: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Other'. return thing.arg; }; \ No newline at end of file diff --git a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt index 6d03f77607637..f3a0aace8ca50 100644 --- a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt +++ b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt @@ -1,10 +1,10 @@ -index.ts(1,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. +index.ts(1,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (1 errors) ==== export const a = async () => (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== node_modules/inner/index.d.ts (0 errors) ==== export { x } from "./other.js"; ==== node_modules/inner/other.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt index 7e86097227b3b..99aaac0aae567 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt index 7e86097227b3b..99aaac0aae567 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt index 7e86097227b3b..99aaac0aae567 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt index 7e86097227b3b..99aaac0aae567 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt index 358a0e61437a1..a2a45afc7d2b7 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt index 358a0e61437a1..a2a45afc7d2b7 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt index 358a0e61437a1..a2a45afc7d2b7 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt index 358a0e61437a1..a2a45afc7d2b7 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js index 058f0c3df8e91..226b9b0dad1ec 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js index 33ee05923f58f..07b762628c229 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ diff --git a/tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts b/tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts new file mode 100644 index 0000000000000..0fddc5b43bcbd --- /dev/null +++ b/tests/cases/compiler/declarationEmitUnsafeImportSymbolName.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @target: es2015 +// @declaration: true +// @filename: r/node_modules/foo/node_modules/nested/index.d.ts +export interface MySpecialType { + val: string; +} +// @filename: r/node_modules/foo/index.d.ts +import { MySpecialType } from "nested"; +export function getSpecial(): MySpecialType; +// @filename: r/entry.ts +import { getSpecial } from "foo"; +export const special = getSpecial(); From 3f19c5224aeebcb746782cd112648a49d09fe593 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:41:32 +0000 Subject: [PATCH 3/6] Update error message format: reference to symbol from module path Co-authored-by: arcanis <1037931+arcanis@users.noreply.github.com> --- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/transformers/declarations.ts | 2 +- ...declarationEmitCommonJsModuleReferencedType.errors.txt | 4 ++-- .../declarationEmitObjectAssignedDefaultExport.errors.txt | 4 ++-- .../declarationEmitReexportedSymlinkReference3.errors.txt | 4 ++-- .../declarationEmitUnsafeImportSymbolName.errors.txt | 4 ++-- .../reference/declarationEmitUsingTypeAlias1.errors.txt | 8 ++++---- ...ModulesExportsSpecifierGenerationConditions.errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node16).errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node18).errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node20).errors.txt | 4 ++-- ...sBlocksSpecifierResolution(module=nodenext).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node16).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node18).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node20).errors.txt | 4 ++-- ...nodeModulesExportsSourceTs(module=nodenext).errors.txt | 4 ++-- ...g-package-through-indirect-symlink-moduleCaseChange.js | 2 +- ...references-sibling-package-through-indirect-symlink.js | 2 +- 18 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0247c9ea5807e..46c280799d7f9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4022,12 +4022,12 @@ "category": "Error", "code": 2882 }, - "The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary. The type originates from symbol '{2}'.": { + "The inferred type of '{0}' cannot be named without a reference to '{2}' from '{1}'. This is likely not portable. A type annotation is necessary.": { "category": "Error", "code": 2883 }, - "Import declaration '{0}' is using private name '{1}'.":{ + "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 }, diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 3b3deb31d5b72..9a8f5adb18cfa 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -411,7 +411,7 @@ export function transformDeclarations(context: TransformationContext): Transform function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string) { if (errorNameNode || errorFallbackNode) { if (symbolName) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary_The_type_originates_from_symbol_2, errorDeclarationNameWithFallback(), specifier, symbolName)); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier, symbolName)); } else { context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier)); diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt index 79feb64c90436..7cc3bfb9b7db9 100644 --- a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt @@ -1,4 +1,4 @@ -r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NestedProps'. +r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. ==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -23,6 +23,6 @@ r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without import { bar } from "root"; export const x = foo(); ~ -!!! error TS2883: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NestedProps'. +!!! error TS2883: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. export const y = bar(); \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt index 3cfebea5198e0..8396aee5921c5 100644 --- a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt +++ b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt @@ -1,4 +1,4 @@ -index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NonReactStatics'. +index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. ==== node_modules/styled-components/node_modules/hoist-non-react-statics/index.d.ts (0 errors) ==== @@ -43,5 +43,5 @@ index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named with ~~~~~ }); ~~~ -!!! error TS2883: The inferred type of 'default' cannot be named without a reference to 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'NonReactStatics'. +!!! error TS2883: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt index a7aa4fe947330..f0520d30e21d8 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -1,4 +1,4 @@ -monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. +monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. ==== monorepo/pkg3/tsconfig.json (0 errors) ==== @@ -21,7 +21,7 @@ monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cann export const ADMIN = MetadataAccessor.create('1'); ~~~~~ -!!! error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. +!!! error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. ==== monorepo/pkg1/dist/index.d.ts (0 errors) ==== export * from './types'; ==== monorepo/pkg1/dist/types.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt index 0b284f10602c6..64c559942c683 100644 --- a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt @@ -1,4 +1,4 @@ -r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'MySpecialType'. +r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. ==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -12,5 +12,5 @@ r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named w import { getSpecial } from "foo"; export const special = getSpecial(); ~~~~~~~ -!!! error TS2883: The inferred type of 'special' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'MySpecialType'. +!!! error TS2883: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt index a10062767f3b1..b243748856549 100644 --- a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt +++ b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt @@ -1,5 +1,5 @@ -src/index.ts(3,14): error TS2883: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'SomeType'. -src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Other'. +src/index.ts(3,14): error TS2883: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. ==== node_modules/some-dep/dist/inner.d.ts (0 errors) ==== @@ -23,12 +23,12 @@ src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named wit export const foo = (thing: SomeType) => { ~~~ -!!! error TS2883: The inferred type of 'foo' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'SomeType'. +!!! error TS2883: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. return thing; }; export const bar = (thing: SomeType) => { ~~~ -!!! error TS2883: The inferred type of 'bar' cannot be named without a reference to '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Other'. +!!! error TS2883: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. return thing.arg; }; \ No newline at end of file diff --git a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt index f3a0aace8ca50..71a7854c0082e 100644 --- a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt +++ b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt @@ -1,10 +1,10 @@ -index.ts(1,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(1,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. ==== index.ts (1 errors) ==== export const a = async () => (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== export { x } from "./other.js"; ==== node_modules/inner/other.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt index 99aaac0aae567..5f2b9b88ecf7a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt index 99aaac0aae567..5f2b9b88ecf7a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt index 99aaac0aae567..5f2b9b88ecf7a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt index 99aaac0aae567..5f2b9b88ecf7a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt index a2a45afc7d2b7..d62434e7004f0 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt index a2a45afc7d2b7..d62434e7004f0 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt index a2a45afc7d2b7..d62434e7004f0 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt index a2a45afc7d2b7..d62434e7004f0 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'Thing'. +!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js index 226b9b0dad1ec..1a499fcd1980c 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. +pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js index 07b762628c229..af85a068e9670 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. The type originates from symbol 'IdType'. +pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ From 28ac0480c0c30547bc2762f39005f60f32e4e6e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:09:22 +0000 Subject: [PATCH 4/6] Reuse error code 2742 instead of 2883 since TS2742 is never emitted without symbol name Co-authored-by: arcanis <1037931+arcanis@users.noreply.github.com> --- src/compiler/checker.ts | 4 ++-- src/compiler/diagnosticMessages.json | 6 +----- src/compiler/transformers/declarations.ts | 7 +------ ...declarationEmitCommonJsModuleReferencedType.errors.txt | 4 ++-- .../declarationEmitObjectAssignedDefaultExport.errors.txt | 4 ++-- .../declarationEmitReexportedSymlinkReference3.errors.txt | 4 ++-- .../declarationEmitUnsafeImportSymbolName.errors.txt | 4 ++-- .../reference/declarationEmitUsingTypeAlias1.errors.txt | 8 ++++---- ...ModulesExportsSpecifierGenerationConditions.errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node16).errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node18).errors.txt | 4 ++-- ...rtsBlocksSpecifierResolution(module=node20).errors.txt | 4 ++-- ...sBlocksSpecifierResolution(module=nodenext).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node16).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node18).errors.txt | 4 ++-- .../nodeModulesExportsSourceTs(module=node20).errors.txt | 4 ++-- ...nodeModulesExportsSourceTs(module=nodenext).errors.txt | 4 ++-- ...g-package-through-indirect-symlink-moduleCaseChange.js | 2 +- ...references-sibling-package-through-indirect-symlink.js | 2 +- 19 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 97bb6ae0d94ee..070c1d2423eda 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6435,7 +6435,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (name.includes("/node_modules/")) { context.encounteredError = true; if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(name); + context.tracker.reportLikelyUnsafeImportRequiredError(name, nodeSymbol ? unescapeLeadingUnderscores(nodeSymbol.escapedName) : undefined); } } if (name !== originalName) { @@ -8717,7 +8717,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // since declaration files with these kinds of references are liable to fail when published :( context.encounteredError = true; if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, chain.length > 1 ? unescapeLeadingUnderscores(symbol.escapedName) : undefined); + context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, unescapeLeadingUnderscores(symbol.escapedName)); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 46c280799d7f9..9cfec002a61cb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3506,7 +3506,7 @@ "category": "Error", "code": 2741 }, - "The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary.": { + "The inferred type of '{0}' cannot be named without a reference to '{2}' from '{1}'. This is likely not portable. A type annotation is necessary.": { "category": "Error", "code": 2742 }, @@ -4022,10 +4022,6 @@ "category": "Error", "code": 2882 }, - "The inferred type of '{0}' cannot be named without a reference to '{2}' from '{1}'. This is likely not portable. A type annotation is necessary.": { - "category": "Error", - "code": 2883 - }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 9a8f5adb18cfa..0a87a12f5af03 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -410,12 +410,7 @@ export function transformDeclarations(context: TransformationContext): Transform function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string) { if (errorNameNode || errorFallbackNode) { - if (symbolName) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier, symbolName)); - } - else { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier)); - } + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier, symbolName ?? specifier)); } } diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt index 7cc3bfb9b7db9..0f75f17110c8e 100644 --- a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt @@ -1,4 +1,4 @@ -r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +r/entry.ts(3,14): error TS2742: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. ==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -23,6 +23,6 @@ r/entry.ts(3,14): error TS2883: The inferred type of 'x' cannot be named without import { bar } from "root"; export const x = foo(); ~ -!!! error TS2883: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'x' cannot be named without a reference to 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. export const y = bar(); \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt index 8396aee5921c5..8dd8176675bea 100644 --- a/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt +++ b/tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt @@ -1,4 +1,4 @@ -index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. +index.ts(7,1): error TS2742: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. ==== node_modules/styled-components/node_modules/hoist-non-react-statics/index.d.ts (0 errors) ==== @@ -43,5 +43,5 @@ index.ts(7,1): error TS2883: The inferred type of 'default' cannot be named with ~~~~~ }); ~~~ -!!! error TS2883: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'default' cannot be named without a reference to 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt index f0520d30e21d8..9c0f688ff3a83 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -1,4 +1,4 @@ -monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. ==== monorepo/pkg3/tsconfig.json (0 errors) ==== @@ -21,7 +21,7 @@ monorepo/pkg3/src/keys.ts(3,14): error TS2883: The inferred type of 'ADMIN' cann export const ADMIN = MetadataAccessor.create('1'); ~~~~~ -!!! error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. ==== monorepo/pkg1/dist/index.d.ts (0 errors) ==== export * from './types'; ==== monorepo/pkg1/dist/types.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt index 64c559942c683..3bf205df536dc 100644 --- a/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt +++ b/tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt @@ -1,4 +1,4 @@ -r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +r/entry.ts(2,14): error TS2742: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. ==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -12,5 +12,5 @@ r/entry.ts(2,14): error TS2883: The inferred type of 'special' cannot be named w import { getSpecial } from "foo"; export const special = getSpecial(); ~~~~~~~ -!!! error TS2883: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'special' cannot be named without a reference to 'MySpecialType' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt index b243748856549..614c0a5a00281 100644 --- a/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt +++ b/tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt @@ -1,5 +1,5 @@ -src/index.ts(3,14): error TS2883: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. -src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +src/index.ts(3,14): error TS2742: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +src/index.ts(7,14): error TS2742: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. ==== node_modules/some-dep/dist/inner.d.ts (0 errors) ==== @@ -23,12 +23,12 @@ src/index.ts(7,14): error TS2883: The inferred type of 'bar' cannot be named wit export const foo = (thing: SomeType) => { ~~~ -!!! error TS2883: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'foo' cannot be named without a reference to 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. return thing; }; export const bar = (thing: SomeType) => { ~~~ -!!! error TS2883: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'bar' cannot be named without a reference to 'Other' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary. return thing.arg; }; \ No newline at end of file diff --git a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt index 71a7854c0082e..a46c9f5523314 100644 --- a/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt +++ b/tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt @@ -1,10 +1,10 @@ -index.ts(1,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. +index.ts(1,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. ==== index.ts (1 errors) ==== export const a = async () => (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/private'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== export { x } from "./other.js"; ==== node_modules/inner/other.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt index 5f2b9b88ecf7a..3969ab7a7b3a0 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt index 5f2b9b88ecf7a..3969ab7a7b3a0 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt index 5f2b9b88ecf7a..3969ab7a7b3a0 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt index 5f2b9b88ecf7a..3969ab7a7b3a0 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== node_modules/inner/index.d.ts (0 errors) ==== // esm format file export { x } from "./other.js"; diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt index d62434e7004f0..4e538d4853e2f 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node16).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt index d62434e7004f0..4e538d4853e2f 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node18).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt index d62434e7004f0..4e538d4853e2f 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=node20).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt index d62434e7004f0..4e538d4853e2f 100644 --- a/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSourceTs(module=nodenext).errors.txt @@ -1,5 +1,5 @@ index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. -index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. ==== index.ts (2 errors) ==== @@ -9,7 +9,7 @@ index.ts(3,14): error TS2883: The inferred type of 'a' cannot be named without a !!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations. export const a = (await import("inner")).x(); ~ -!!! error TS2883: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. +!!! error TS2742: The inferred type of 'a' cannot be named without a reference to 'Thing' from './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary. import {a as a2} from "package"; ==== node_modules/inner/index.ts (0 errors) ==== // esm format file diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js index 1a499fcd1980c..84d025b788529 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js index af85a068e9670..48505c81c2c2b 100644 --- a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js @@ -81,7 +81,7 @@ declare const console: { log(msg: any): void; }; /home/src/tslibs/TS/Lib/tsc.js -p pkg3 --explainFiles Output:: -pkg3/src/keys.ts:2:14 - error TS2883: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. +pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. 2 export const ADMIN = MetadataAccessor.create('1');    ~~~~~ From bb5680c18973ae9f1ea954740bc37a730117b151 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:30:06 +0000 Subject: [PATCH 5/6] Make symbolName required in reportLikelyUnsafeImportRequiredError Co-authored-by: arcanis <1037931+arcanis@users.noreply.github.com> --- src/compiler/checker.ts | 6 +++--- src/compiler/transformers/declarations.ts | 4 ++-- src/compiler/types.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 070c1d2423eda..56e627ef23395 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6434,8 +6434,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (name.includes("/node_modules/")) { context.encounteredError = true; - if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(name, nodeSymbol ? unescapeLeadingUnderscores(nodeSymbol.escapedName) : undefined); + if (context.tracker.reportLikelyUnsafeImportRequiredError && nodeSymbol) { + context.tracker.reportLikelyUnsafeImportRequiredError(name, unescapeLeadingUnderscores(nodeSymbol.escapedName)); } } if (name !== originalName) { @@ -54370,7 +54370,7 @@ class SymbolTrackerImpl implements SymbolTracker { } } - reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string): void { + reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string): void { if (this.inner?.reportLikelyUnsafeImportRequiredError) { this.onDiagnosticReported(); this.inner.reportLikelyUnsafeImportRequiredError(specifier, symbolName); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 0a87a12f5af03..6f26ab96be1ea 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -408,9 +408,9 @@ export function transformDeclarations(context: TransformationContext): Transform } } - function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName?: string) { + function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier, symbolName ?? specifier)); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_type_annotation_is_necessary, errorDeclarationNameWithFallback(), specifier, symbolName)); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9291b037dbb3c..374c1988494c8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -10050,7 +10050,7 @@ export interface SymbolTracker { reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; reportCyclicStructureError?(): void; - reportLikelyUnsafeImportRequiredError?(specifier: string, symbolName?: string): void; + reportLikelyUnsafeImportRequiredError?(specifier: string, symbolName: string): void; reportTruncationError?(): void; moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string; }; reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void; From 2f950931330ef0132ce49edc541f0e963b1e9edb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:50:59 +0000 Subject: [PATCH 6/6] Use symbolName() function instead of unescapeLeadingUnderscores(symbol.escapedName) Co-authored-by: arcanis <1037931+arcanis@users.noreply.github.com> --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56e627ef23395..8239165385863 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6435,7 +6435,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (name.includes("/node_modules/")) { context.encounteredError = true; if (context.tracker.reportLikelyUnsafeImportRequiredError && nodeSymbol) { - context.tracker.reportLikelyUnsafeImportRequiredError(name, unescapeLeadingUnderscores(nodeSymbol.escapedName)); + context.tracker.reportLikelyUnsafeImportRequiredError(name, symbolName(nodeSymbol)); } } if (name !== originalName) { @@ -8717,7 +8717,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // since declaration files with these kinds of references are liable to fail when published :( context.encounteredError = true; if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, unescapeLeadingUnderscores(symbol.escapedName)); + context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, symbolName(symbol)); } } }