-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Feat/quick fix for types #42126
Feat/quick fix for types #42126
Conversation
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.
It's impressive how much those two lines of code are doing. However, I only want to offer the codefix for the case where the did-you-mean applies and is offered. That means adding did-you-mean errors for Cannot_find_name_0 and hooking them up properly to type resolution.
I think what you said is reasonable, I can have a try |
…st when resolve type
… feat/quick-fix-for-types
It has been modified. If you are free, please help to check it @sandersn |
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.
Sorry for the long wait. I have two suggestions:
- Unconditionally issue suggestions in
resolveName
if errors are requested. - Make sure that
string
is suggested beforeString
, as well as for the other primitive types.
I realise I dropped the ball on this, so if you don't have time or energy to finish this PR, I can take over.
fixId: "fixSpelling", | ||
fixAllDescription: "Fix all detected spelling errors", | ||
newFileContent: | ||
`declare let a: Number; |
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.
Strange that this doesn't correct to number
after #39060. Good to look at for future work.
@@ -1,12 +1,13 @@ | |||
/a.js(3,15): error TS2304: Cannot find name 'sting'. | |||
/a.js(3,15): error TS2552: Cannot find name 'sting'. Did you mean 'String'? |
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.
hmm, this also needs to suggest string
not String
. We might need to improve the suggestion code, perhaps with a special case for string/number/boolean/object (and any others?).
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.
Looks like string/number/boolean/object/bigint
etc are missing from the list of global suggestions.
Edit: That's because the intrinsic types are resolved via direct lookup and don't have symbols.
src/compiler/checker.ts
Outdated
@@ -3080,7 +3080,7 @@ namespace ts { | |||
/** | |||
* Resolves a qualified name and any involved aliases. | |||
*/ | |||
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined { | |||
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node, needSuggestedNameNotFoundMessage?: boolean): Symbol | undefined { |
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.
what happens if you don't add needSuggestedNameNotFoundMessage
and always request suggestions? It only makes a difference for resolveName
calls that pass the combination nameNotFoundMessage = undefined
and issueSuggestions = true
. I'll go see if any calls like that exist.
Edit: I checked. The only new places that would issue suggestions is resolution for globals and JSX built-in symbols, only if they already request errors. This is fine. You can delete needSuggestedNameNotFoundMessage
and issueSuggestions
and unconditionally issue suggestions in resolveName
if message
is defined.
src/compiler/checker.ts
Outdated
suggestedNameNotFoundMessage = Diagnostics.Cannot_find_name_0_Did_you_mean_1; | ||
} | ||
} | ||
symbol = getMergedSymbol(resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true, false, suggestedNameNotFoundMessage)); |
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.
resolveName
now takes a boolean issueSuggestions
instead of a message. I think it's probably fine to move your new code to choose the message inside resolveName
.
Update: I tried unconditionally suggesting errors and it works fine. I pushed the change with changed baselines to the branch always-suggest-spelling-correction |
Even for types. Based on #42126, but without the namespace-specific error message.
@sandersn If you have time, please help me to complete this PR, I have been busy recently |
Instead of altering wrappers to look like primitives.
Fixes #40314
It's easy to fix the code below.
before:
after:
@DanielRosenwasser please help see this