Skip to content

"Move to new file" does not copy React import #27937

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.1.3

Search Terms: react umd "move to new file" refactor

Code

// ./src/index.tsx
import * as React from 'react';

const MyComponent: React.SFC<{}> = props => <div />;

export default MyComponent;
{
    "compilerOptions": {
        "jsx": "react"
    },
    "include": ["./src/**/*"]
}

Expected behavior:
When copying the line const MyComponent and actioning the "Move to new file" command, the new file contents should be:

import * as React from 'react';
export const MyComponent: React.SFC<{}> = props => <div />;

Actual behavior:
The new file contents are:

export const MyComponent: React.SFC<{}> = props => <div />;

The React import is missing, which creates errors:

// React import is missing…
export const MyComponent: SFC<{}> = props =>
  // … which results in error: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
  <div />;

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterDomain: Refactoringse.g. extract to constant or function, rename symbol

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions