Skip to content

Build better import paths for declaration emit/typeToString from reexports if possible - #27340

Merged
Wesley Wigham (weswigham) merged 8 commits into
microsoft:masterfrom
weswigham:lookup-reexports-for-better-imports
Nov 13, 2018
Merged

Wesley Wigham (weswigham) merged 8 commits into
microsoft:masterfrom
weswigham:lookup-reexports-for-better-imports

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Sep 25, 2018 •

Copy link
Copy Markdown
Member

Also, issue an error on relative/deep node_modules import generation (under moduleResolution: "node") if a better specifier cannot be found (which can happen if your type definitions need to depend on the types of a dependency of a dependency which you do not yet directly depend on). While such paths technically work on the compiling system, the resulting .d.ts file will be non-portable; this can cause issues for package consumers, so it is best to mark it as needing a type annotation to fix the problem.

Fixes #26985

@weswigham

Copy link
Copy Markdown
Member Author
@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2018 •

Copy link
Copy Markdown
Contributor

Heya Wesley Wigham (@weswigham), I've started to run the extended test suite on this PR at 4f50766. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham

Copy link
Copy Markdown
Member Author

Andy (Andrewkraft) (@Andy-MS) you wanna look over this?

Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
@weswigham

Copy link
Copy Markdown
Member Author
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Message",
"code": 2738
},
"The inferred type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is {1} the name of the package? Or the module itself?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Generating a declaration for '{0}' requires generating a reference to the module '{1}'; however, this is susceptible to breaking upon distribution. Provide an explicit annotation or add an explicit dependency on '{2}'.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the new test:

The inferred type of 'x' requires a reference to a module at 'foo/node_modules/nested' to name, which would likely break on type redistribution. A type annotation is necessary.

It's the specifier we would generate were we to emit it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an accessibility error

"The inferred type of '{0}' references an inaccessible '{1}' type. A type annotation is necessary."

which this message is templated after. I imagine we should use consistent language.

@rbuckton Ron Buckton (rbuckton) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barring Daniel's feedback and a minor nitpick, this seems fine.

Comment thread src/compiler/checker.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nesting is unnecessarily complicated. What about this:

let results = links.extendedContainersByFile && links.extendedContainersByFile.get(id);
if (results) return results;
Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Error",
"code": 2741
},
"The inferred type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming the type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.

or

``
Generating a declaration for the type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary. ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

4 participants