-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #15540: Throw error when importing @types #15866
Conversation
@nowy, It will cover your contributions to all Microsoft-managed open source projects. |
3335ece
to
1764ff9
Compare
Fix issue: microsoft#15540 - Modify checker; external imports to account for imported modules containing '@types/'. - Add diagnostic message. - Add test case
@nowy, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
@Andy-MS can you please review this change. |
src/compiler/checker.ts
Outdated
@@ -1642,6 +1642,11 @@ namespace ts { | |||
return; | |||
} | |||
|
|||
if (moduleReference.substr(0, 7) === "@types/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startsWith(moduleReference, "@types/")
src/compiler/checker.ts
Outdated
@@ -1642,6 +1642,11 @@ namespace ts { | |||
return; | |||
} | |||
|
|||
if (moduleReference.substr(0, 7) === "@types/") { | |||
const diag = Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1; | |||
error(errorNode, diag, moduleReference.substr(7), moduleReference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a removePrefix
helper like in #15545. (At the same place and with the same text, so that these PRs can merge together.)
src/compiler/diagnosticMessages.json
Outdated
@@ -2135,6 +2135,10 @@ | |||
"category": "Error", | |||
"code": 2710 | |||
}, | |||
"Cannot import type declaration files. Consider importing '{0}' instead of '{1}'.": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put at 6137 near other module resolution diagnostics.
- Replace `substr` with `startsWith` - move diagnostics message to more relevant place - Add `removePrefix` helper function
@Andy-MS all done. Thanks for such a quick review! |
@Andy-MS when do you think this will this get released? |
Fix issue: #15540
containing '@types/'.
Fixes #15540