Don't recommend to install '@types/foo' if that already exists (#24815)

* Don't recommend to install '@types/foo' if that already exists

* Add different extra diagnostic text if the @types package exists

* Update API (#24966)
This commit is contained in:
Andy
2018-06-21 10:19:14 -07:00
committed by GitHub
parent e7b338e943
commit 2b9166b2f9
8 changed files with 135 additions and 5 deletions

View File

@@ -2283,16 +2283,24 @@ namespace ts {
}
function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void {
const errorInfo = packageId && chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
getMangledNameForScopedPackage(packageId.name));
const errorInfo = packageId
? chainDiagnosticMessages(
/*details*/ undefined,
typesPackageExists(packageId.name)
? Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_0
: Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
getMangledNameForScopedPackage(packageId.name))
: undefined;
errorOrSuggestion(isError, errorNode, chainDiagnosticMessages(
errorInfo,
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
moduleReference,
resolvedFileName));
}
function typesPackageExists(packageName: string): boolean {
return host.getSourceFiles().some(sf => !!sf.resolvedModules && !!forEachEntry(sf.resolvedModules, r =>
r && r.packageId && r.packageId.name === getTypesPackageName(packageName)));
}
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
// and an external module with no 'export =' declaration resolves to the module itself.

View File

@@ -3636,7 +3636,7 @@
"category": "Message",
"code": 6353
},
"Project '{0}' is up to date with .d.ts files from its dependencies": {
"category": "Message",
"code": 6354
@@ -3836,6 +3836,10 @@
"category": "Error",
"code": 7039
},
"If the '{0}' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/{0}`": {
"category": "Error",
"code": 7040
},
"You cannot rename this element.": {
"category": "Error",
"code": 8000