Skip to content
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

missing import code action tries to import React unnecessarily #623

Closed
davidhu2000 opened this issue Nov 14, 2022 · 4 comments
Closed

missing import code action tries to import React unnecessarily #623

davidhu2000 opened this issue Nov 14, 2022 · 4 comments

Comments

@davidhu2000
Copy link

davidhu2000 commented Nov 14, 2022

In the case below where we are missing import { Image } from 'react-native';

import { render } from '@testing-library/react-native';

describe('test lsp', () => {
  render(<Image />);
});

the available code action from the tsserver are
Screen Shot 2022-11-14 at 12 08 24 PM

because we are using react-18, importing react is unnecessary.

After adding

import React from' react';

then the code actions work

Screen Shot 2022-11-14 at 12 09 05 PM

the Add import from "react-native" should show up on the first try.

typescript-language-server --version
2.1.0
@rchl
Copy link
Member

rchl commented Nov 14, 2022

Are you able to provide a minimal project that reproduces this issue?

@davidhu2000
Copy link
Author

davidhu2000 commented Nov 15, 2022

@rchl, I created a quick repo to reproduce. https://github.com/davidhu2000/ts-lsp-import-bug

I did someadditional tests, and it appears that the following option works

{
  "compilerOptions": {
    "jsx": "react-jsx",

however, jsx: 'react-native' or jsx: react does not work. does this mean this is a typescript issue?

Possibly related? microsoft/TypeScript#41762

@rchl
Copy link
Member

rchl commented Nov 23, 2022

Possibly related? microsoft/TypeScript#41762

I suppose so.
If this also works the same in VSCode then most definitively something that Typescript might need to handle.

@davidhu2000
Copy link
Author

Yeah. Also happening in VS Code, l I'll open an issue with typescript

@davidhu2000 davidhu2000 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants