Skip to content

Convert 'installTypesForPackge' refactor to a suggestion #22267

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

Merged
4 commits merged into from
Mar 1, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Mar 1, 2018

In #19130, had to add duplicate code fix and refactor -- now it's just a code fix and we give a suggestion instead of error diagnostic if --noImplicitAny isn't enabled.

Note that I had to make a separate diagnostic for the suggestion; this is because each diagnostic is hard-coded with its category. It seems like we could base that on where the diagnostic is coming from instead? Something coming from the parser/checker is an error, something coming from computeSuggestionDiagnostics is a suggestion. This will be a bigger problem when I add suggestion diagnostics for unused variables, since we have a lot of different diagnostics for those.

@ghost ghost requested review from mhegazy and amcasey March 1, 2018 18:14
@ghost ghost changed the title Install types Convert 'installTypesForPackge' refactor to a suggestion Mar 1, 2018
}
}

export function willAllowImplicitAnyJsModule(options: CompilerOptions): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

/* @internal */

Copy link
Contributor

Choose a reason for hiding this comment

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

consider moving this to untilities next to getAllowSyntheticDefaultImports and getStricitOptionValue

return options.allowJs || !getStrictOptionValue(options, "noImplicitAny");
}

export function createDiagnosticForModuleMissingTypes(errorNode: Node, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string, diag: DiagnosticMessage): Diagnostic {
Copy link
Contributor

Choose a reason for hiding this comment

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

and here too /* @internal */

Copy link
Contributor

Choose a reason for hiding this comment

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

consider moving them to utilities

@@ -3818,6 +3818,10 @@
"category": "Suggestion",
"code": 80001
},
"Did not find a declaration file for module '{0}'. '{1}' implicitly has an 'any' type.": {
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably should take your suggestion of converting an error diagnostic to a suggestion diagnostic.

@@ -2416,10 +2416,26 @@ namespace ts {
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
}
function needAllowJs() {
return options.allowJs || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
return willAllowImplicitAnyJsModule(options) ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do not we instead log the diagnostic in a different list, a suggestions list. the command line compiler will never report them, but we can query them in the services and add additional messages there as well..

@ghost ghost force-pushed the installTypes branch from 532600c to ff2fd15 Compare March 1, 2018 20:55
…ing work in calculateSuggestionDiagnostics
@ghost ghost force-pushed the installTypes branch from ff2fd15 to 177a43c Compare March 1, 2018 20:56
@ghost ghost merged commit 16fc256 into master Mar 1, 2018
@ghost ghost deleted the installTypes branch March 1, 2018 22:41
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant