Skip to content

Commit ce3be12

Browse files
committed
Feedback
1 parent dbc310a commit ce3be12

20 files changed

+48
-39
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6434,8 +6434,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
64346434
}
64356435
if (name.includes("/node_modules/")) {
64366436
context.encounteredError = true;
6437-
if (context.tracker.reportLikelyUnsafeImportRequiredError && nodeSymbol) {
6438-
context.tracker.reportLikelyUnsafeImportRequiredError(name, unescapeLeadingUnderscores(nodeSymbol.escapedName));
6437+
if (context.tracker.reportLikelyUnsafeImportRequiredError) {
6438+
context.tracker.reportLikelyUnsafeImportRequiredError(name, nodeSymbol ? unescapeLeadingUnderscores(nodeSymbol.escapedName) : undefined);
64396439
}
64406440
}
64416441
if (name !== originalName) {
@@ -54370,7 +54370,7 @@ class SymbolTrackerImpl implements SymbolTracker {
5437054370
}
5437154371
}
5437254372

54373-
reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string): void {
54373+
reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string | undefined): void {
5437454374
if (this.inner?.reportLikelyUnsafeImportRequiredError) {
5437554375
this.onDiagnosticReported();
5437654376
this.inner.reportLikelyUnsafeImportRequiredError(specifier, symbolName);

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,7 @@
35063506
"category": "Error",
35073507
"code": 2741
35083508
},
3509-
"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.": {
3509+
"The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary.": {
35103510
"category": "Error",
35113511
"code": 2742
35123512
},
@@ -4022,6 +4022,10 @@
40224022
"category": "Error",
40234023
"code": 2882
40244024
},
4025+
"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.": {
4026+
"category": "Error",
4027+
"code": 2883
4028+
},
40254029

40264030
"Import declaration '{0}' is using private name '{1}'.": {
40274031
"category": "Error",

src/compiler/transformers/declarations.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,14 @@ export function transformDeclarations(context: TransformationContext): Transform
408408
}
409409
}
410410

411-
function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string) {
411+
function reportLikelyUnsafeImportRequiredError(specifier: string, symbolName: string | undefined) {
412412
if (errorNameNode || errorFallbackNode) {
413-
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));
413+
if (symbolName) {
414+
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));
415+
}
416+
else {
417+
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));
418+
}
414419
}
415420
}
416421

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10050,7 +10050,7 @@ export interface SymbolTracker {
1005010050
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
1005110051
reportInaccessibleUniqueSymbolError?(): void;
1005210052
reportCyclicStructureError?(): void;
10053-
reportLikelyUnsafeImportRequiredError?(specifier: string, symbolName: string): void;
10053+
reportLikelyUnsafeImportRequiredError?(specifier: string, symbolName: string | undefined): void;
1005410054
reportTruncationError?(): void;
1005510055
moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string; };
1005610056
reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void;

tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
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.
22

33

44
==== 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
2323
import { bar } from "root";
2424
export const x = foo();
2525
~
26-
!!! 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.
26+
!!! 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.
2727
export const y = bar();
2828

tests/baselines/reference/declarationEmitObjectAssignedDefaultExport.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
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.
22

33

44
==== 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
4343
~~~~~
4444
});
4545
~~~
46-
!!! 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.
46+
!!! 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.
4747

tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
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.
22

33

44
==== 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
2121

2222
export const ADMIN = MetadataAccessor.create<boolean>('1');
2323
~~~~~
24-
!!! 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.
24+
!!! 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.
2525
==== monorepo/pkg1/dist/index.d.ts (0 errors) ====
2626
export * from './types';
2727
==== monorepo/pkg1/dist/types.d.ts (0 errors) ====

tests/baselines/reference/declarationEmitUnsafeImportSymbolName.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
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.
22

33

44
==== r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ====
@@ -12,5 +12,5 @@ r/entry.ts(2,14): error TS2742: The inferred type of 'special' cannot be named w
1212
import { getSpecial } from "foo";
1313
export const special = getSpecial();
1414
~~~~~~~
15-
!!! 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.
15+
!!! 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.
1616

tests/baselines/reference/declarationEmitUsingTypeAlias1.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
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.
2-
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.
1+
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.
2+
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.
33

44

55
==== 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
2323

2424
export const foo = (thing: SomeType) => {
2525
~~~
26-
!!! 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.
26+
!!! 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.
2727
return thing;
2828
};
2929

3030
export const bar = (thing: SomeType) => {
3131
~~~
32-
!!! 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.
32+
!!! 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.
3333
return thing.arg;
3434
};

tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
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.
1+
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.
22

33

44
==== index.ts (1 errors) ====
55
export const a = async () => (await import("inner")).x();
66
~
7-
!!! 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.
7+
!!! 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.
88
==== node_modules/inner/index.d.ts (0 errors) ====
99
export { x } from "./other.js";
1010
==== node_modules/inner/other.d.ts (0 errors) ====

0 commit comments

Comments
 (0)