Skip to content

Import fix creates incorrect URL for symbols from preact/hooks #37542

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
cmlenz opened this issue Mar 23, 2020 · 2 comments · Fixed by #37561
Closed

Import fix creates incorrect URL for symbols from preact/hooks #37542

cmlenz opened this issue Mar 23, 2020 · 2 comments · Fixed by #37561
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@cmlenz
Copy link

cmlenz commented Mar 23, 2020

TypeScript Version: 3.8.3

Search Terms:
import preact/hooks preact/hooks/src

Code

import {h} from 'preact';

function App(): void {
  const value = useMemo(() => 'Hello');
  return <div>{state}</div>;
}

Run missing import fix on useMemo.

Expected behavior:

The quick fix should add the import line

import {useMemo} from 'preact/hooks';

Actual behavior:

The quick fix actually adds the incorrect import line

import {useMemo} from 'preact/hooks/src';

This will cause the source files from Preact to be bundled instead of the transpiled files, which will cause various kinds of breakage (see preactjs/preact#1757 or preactjs/preact#1373).

@sheetalkamat
Copy link
Member

Please demonstrate the problem with detail since just creating the file does not give code fix as program doesn't have anything except jsx.d.ts and index.d.ts from preact included. Also try out typescript@next to see if the issue repros.

c:/Typescript/built/local/lib.d.ts
	c:/Typescript/built/local/lib.es5.d.ts
	c:/Typescript/built/local/lib.dom.d.ts
	c:/Typescript/built/local/lib.webworker.importscripts.d.ts
	c:/Typescript/built/local/lib.scripthost.d.ts
	c:/temp/temp/node_modules/preact/src/jsx.d.ts
	c:/temp/temp/node_modules/preact/src/index.d.ts
	c:/temp/temp/a.tsx

@sheetalkamat sheetalkamat added the Needs More Info The issue still hasn't been fully clarified label Mar 23, 2020
@cmlenz
Copy link
Author

cmlenz commented Mar 24, 2020

I have prepared a minimal reproduction for the issue we are seeing here:

https://github.com/mediatis/ts37542-preact-autoimport

It turns out that I needed to have a second file in the project that imports from preact/hooks. When that is in place, attempting to quick fix a missing import in another file will suggest preact/hooks/src.

The repo above contains step by step instructions for reproduction in the README. Also it is set up to use typescript@next.

@sheetalkamat sheetalkamat added Needs Investigation This issue needs a team member to investigate its status. and removed Needs More Info The issue still hasn't been fully clarified labels Mar 24, 2020
@sheetalkamat sheetalkamat self-assigned this Mar 24, 2020
@sheetalkamat sheetalkamat added the Fix Available A PR has been opened for this issue label Mar 24, 2020
@sheetalkamat sheetalkamat added this to the TypeScript 3.9.0 milestone Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants