Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (b *NodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl
// If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error
// since declaration files with these kinds of references are liable to fail when published :(
b.ctx.encounteredError = true
b.ctx.tracker.ReportLikelyUnsafeImportRequiredError(oldSpecifier)
b.ctx.tracker.ReportLikelyUnsafeImportRequiredError(oldSpecifier, symbol.Name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/checker/symboltracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func (this *SymbolTrackerImpl) ReportCyclicStructureError() {
this.inner.ReportCyclicStructureError()
}

func (this *SymbolTrackerImpl) ReportLikelyUnsafeImportRequiredError(specifier string) {
func (this *SymbolTrackerImpl) ReportLikelyUnsafeImportRequiredError(specifier string, symbolName string) {
this.onDiagnosticReported()
if this.inner == nil {
return
}
this.inner.ReportLikelyUnsafeImportRequiredError(specifier)
this.inner.ReportLikelyUnsafeImportRequiredError(specifier, symbolName)
}

func (this *SymbolTrackerImpl) ReportTruncationError() {
Expand Down
2 changes: 1 addition & 1 deletion internal/nodebuilder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SymbolTracker interface {
ReportPrivateInBaseOfClassExpression(propertyName string)
ReportInaccessibleUniqueSymbolError()
ReportCyclicStructureError()
ReportLikelyUnsafeImportRequiredError(specifier string)
ReportLikelyUnsafeImportRequiredError(specifier string, symbolName string)
ReportTruncationError()
ReportNonlocalAugmentation(containingFile *ast.SourceFile, parentSymbol *ast.Symbol, augmentingSymbol *ast.Symbol)
ReportNonSerializableProperty(propertyName string)
Expand Down
8 changes: 6 additions & 2 deletions internal/transformers/declarations/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ func (s *SymbolTrackerImpl) ReportInferenceFallback(node *ast.Node) {
}

// ReportLikelyUnsafeImportRequiredError implements checker.SymbolTracker.
func (s *SymbolTrackerImpl) ReportLikelyUnsafeImportRequiredError(specifier string) {
func (s *SymbolTrackerImpl) ReportLikelyUnsafeImportRequiredError(specifier string, symbolName string) {
location := s.errorLocation()
if location != nil {
s.state.addDiagnostic(createDiagnosticForNode(location, diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, s.errorDeclarationNameWithFallback(), specifier))
if symbolName != "" {
s.state.addDiagnostic(createDiagnosticForNode(location, 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, s.errorDeclarationNameWithFallback(), specifier, symbolName))
} else {
s.state.addDiagnostic(createDiagnosticForNode(location, diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, s.errorDeclarationNameWithFallback(), specifier))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 '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) ====
Expand All @@ -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 'NestedProps' from 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary.
export const y = bar();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 '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) ====
Expand Down Expand Up @@ -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 'NonReactStatics' from 'styled-components/node_modules/hoist-non-react-statics'. This is likely not portable. A type annotation is necessary.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 'IdType' from '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary.


==== monorepo/pkg3/tsconfig.json (0 errors) ====
Expand All @@ -21,7 +21,7 @@ monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cann

export const ADMIN = MetadataAccessor.create<boolean>('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 '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) ====
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
r/entry.ts(2,14): error TS2742: 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.
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) ====
Expand All @@ -12,5 +12,5 @@ r/entry.ts(2,14): error TS2742: The inferred type of 'special' cannot be named w
import { getSpecial } from "foo";
export const special = getSpecial();
~~~~~~~
!!! error TS2742: 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.
!!! 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.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 '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(7,14): error TS2883: The inferred type of 'bar' 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.


==== node_modules/some-dep/dist/inner.d.ts (0 errors) ====
Expand All @@ -18,17 +19,19 @@ src/index.ts(7,14): error TS2742: The inferred type of 'bar' cannot be named wit
}
}

==== src/index.ts (2 errors) ====
==== src/index.ts (3 errors) ====
import { SomeType } from "some-dep";

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 '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 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 'Other' from '../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 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary.
return thing.arg;
};
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
--- old.declarationEmitUsingTypeAlias1.errors.txt
+++ new.declarationEmitUsingTypeAlias1.errors.txt
@@= skipped -0, +0 lines =@@
-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 '../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 '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(7,14): error TS2883: The inferred type of 'bar' 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.


==== node_modules/some-dep/dist/inner.d.ts (0 errors) ====
@@= skipped -22, +22 lines =@@
@@= skipped -17, +18 lines =@@
}
}

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 '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary.
return thing;
};
-==== src/index.ts (2 errors) ====
+==== src/index.ts (3 errors) ====
import { SomeType } from "some-dep";

export const foo = (thing: SomeType) => {
@@= skipped -12, +12 lines =@@
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 '../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 'Other' from '../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 'SomeType' from '../node_modules/some-dep/dist/inner'. This is likely not portable. A type annotation is necessary.
return thing.arg;
};
Original file line number Diff line number Diff line change
@@ -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 '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 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 '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) ====
Expand Down
Loading