-
Notifications
You must be signed in to change notification settings - Fork 12.9k
feat: add a codefix to fix class to className in react & add spelling suggest for JSX attributes #37907
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: add a codefix to fix class to className in react & add spelling suggest for JSX attributes #37907
Conversation
I don't know how JSX name resolution works here, but I'm surprised that it's a type assignability error instead of a name resolution error. If it were the latter, you could probably just special-case the spelling correction algorithm and use the existing did-you-mean codefix. Switching which error is issued actually might be the right fix for this. |
I manually do this all the time! |
Yes, in my last try I tried to use it but it seems like JSX never emit diag 2551 ( // The following 2 property both misspelled with doubled last letter
const x = <a onCompositionUpdateCapturee={() => {}} />;
// Property '...' does not exist on type '...'.ts(2322)
window.AbortControllerr
// Property '...' does not exist on type '...'. Did you mean '...'?ts(2551) I'll try to investigate this again |
Oh I found a comment: https://github.com/microsoft/TypeScript/blob/c219fdae08607e07ec875d2137fcba7c2d93792c/src/compiler/checker.ts#L15984 🤔 let me try it |
1513326
to
769c52c
Compare
@andrewbranch |
Done. I'll add some test for it later |
Test added. ready for review |
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.
🌟
@sheetalkamat are you OK with this change now? @andrewbranch likes it at least =) |
I think it's cross-language interference. This is like an editor that lets you paste in Norwegian and offers to translate it to Swedish. |
This reverts commit 1513326.
78c5f67
to
4fce495
Compare
const propName = symbolToString(prop); | ||
const suggestionSymbol = getSuggestedSymbolForNonexistentJSXAttribute(propName, errorTarget); | ||
const suggestion = suggestionSymbol ? symbolToString(suggestionSymbol) : undefined; | ||
if (suggestion) reportError(Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName, typeToString(errorTarget), suggestion); |
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.
There's technically the possibility of an empty symbol name here, but not clear when that comes up.
Also, as a nit, whenever we have an if/else
pair we generally wrap those in curlies.
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.
how to handle a symbol without name?
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.
if (suggestion !== undefined)
Thanks @Jack-Works! |
Add a code fix to fix
class
in JSX (toclassName
) orfor
in JSX (tohtmlFor
). This is useful for copy-paste HTML code into a JSX file.Before:

After (fix all):
