Skip to content

Regression issue with React import when using "jsx": "react" compiler #59117

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

Closed
patrickracicot opened this issue Jul 2, 2024 · 2 comments Β· Fixed by #59193
Closed

Regression issue with React import when using "jsx": "react" compiler #59117

patrickracicot opened this issue Jul 2, 2024 · 2 comments Β· Fixed by #59193
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@patrickracicot
Copy link

patrickracicot commented Jul 2, 2024

πŸ”Ž Search Terms

"verbatimModuleSyntax", "ts6133, "react", "jsx"

πŸ•— Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.3

⏯ Playground Link

https://www.typescriptlang.org/play/?noUnusedLocals=true&noUnusedParameters=true&target=7&verbatimModuleSyntax=true&isolatedModules=false&allowSyntheticDefaultImports=false#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AocpAD0ljkwFcA7DYCZuAYV0maWYwAjAAoAlHADe5OHCIxGUTgB4AJsABucAPQA+CgF9yQA

πŸ’» Code

import React from 'react';

export function Component1() {
  return <div />;
}

πŸ™ Actual behavior

When using "jsx": "react" in the compiler option, we are still required to import React in our components. Now with the version 5.5 of typescript doing such import in conjunction with verbatimModuleSyntax returns an unused import error because the code doesn't directly refer to the React import before its transpiled.

πŸ™‚ Expected behavior

This kind of import should not raise any errors as this is required for the code to work at runtime.

Additional information about the issue

No response

@andrewbranch andrewbranch self-assigned this Jul 5, 2024
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Jul 5, 2024
@andrewbranch andrewbranch added this to the TypeScript 5.5.3 milestone Jul 5, 2024
@jakebailey
Copy link
Member

Bisects to #58366.

@jakebailey
Copy link
Member

Notably, the new code there explicitly skips all reference marks in verbatimModuleSyntax, while the old code did this unconditionally for JSX (and other cases, it seems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
4 participants