Skip to content

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

Closed
@patrickracicot

Description

@patrickracicot

πŸ”Ž 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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions