Skip to content

Organize imports removes react imports in js projects that don't configure "jsx" #23287

Closed
@mjbvz

Description

@mjbvz

From microsoft/vscode#47287

TypeScript Version: 2.9.0-dev.20180409

Search Terms:

  • organize imports
  • jsx

Code
For a simple js project that does not configure "jsx:

jsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2016",
        "experimentalDecorators": true
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

index.js:

import * as React from 'react'

const Button = () => <button />
  1. Run organize imports

Problem:
Typescript (correctly from its perspective) removes the React import as React is not referenced anywhere. However this is very confusing for users.

Proposal:
Some ideas:

  • Special case React imports for files that use jsx even when you don't have "jsx" configured

  • Default "jsx" on for jsconfig projects (the jsconfigs that vscode generates for users already do this). Allow the config to turn if off it a user really needs to

  • Show an editor suggestion on jsx in js files that are part of a jsconfig project that does not configure "jsx"

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterDomain: Organize ImportsIssues with the organize imports featureDomain: Quick FixesEditor-provided fixes, often called code actions.FixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions