-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
type imports are not removed #1525
Comments
I think this behavior is right, since the TypeScript Docs said:
As of vite, I think it can do a hack in transforming, since you always want valid javascript output. |
It does preserve imports, but still removes types. So this code import { Type } from "./module"; will be transformed into import "./module"; |
I get it. However I'm in doubt that esbuild could do this checking, since it only knows some names not in use, instead of knowing which of them are types. So this code import { a, Type } from "./module"
let x: Type = 1 will be transformed into (when import "./module"
let x = 1 Emm, it looks fine though. |
ESBuild transforms this import { T, v } from "./module";
let t: T; into this let t; when So I guess with import "./module";
let t; which would match what tsc does exactly. |
Yeah, that's what tsc does |
TypeScript might be changing their behavior for this soon. See microsoft/TypeScript#43393 and microsoft/TypeScript#44619. I think the new behavior will be something like |
See vitejs/vite#4581 And evanw/esbuild#1525 This lead to npm run watch not working when upgrading svelte kit which in turn updated vite to 2.5
4.5 is out soon, but is still in beta. Doing |
The new behavior does not necessarily relate to what the expected existing behavior is. Essentially it comes down to what is inside the
For ESbuild this means:
|
This has now been released: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#preserve-value-imports. So I plan to implement support for |
In TypeScript modules type imports are not removed, unless
importsNotUsedAsValues
is"remove"
.Given
tsconfg.json
module.ts
main.ts
ESBuild emits
Which is not correct, because valid TypeScript is transformed into invalid JavaScript.
Note that
tsc
does not emit an error in that case despite what one might think"importsNotUsedAsValues": "error"
means.Basically, type imports should be removed always.
Update:
To clarify: import statements should be preserved, but imported types should still be removed.
So this code
woud be transformed into
Related issue: vitejs/vite#4581
Repro: esbuild-type-import-repro
The text was updated successfully, but these errors were encountered: