-
Notifications
You must be signed in to change notification settings - Fork 5.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
feat(unstable): enable importsNotUsedAsValues #7413
feat(unstable): enable importsNotUsedAsValues #7413
Conversation
This PR is a blocker for |
Theoretically we shouldn't need We need this now, but it should be a milestone for swc / swc integration to only require |
@lucacasonato do you have a repro of something that works with I agree we should turn it on though. |
Ah, found the problem. SWC does omit imports not used as values. However it incorrectly requires the import to be used at least once as a type to do this. So this is an SWC bug, and it only occurs in the edge case of completely unused imports. No hurry to address it with this option. cc @kdy1 Off-topic(Another problem: `import { usedAsTypeOnly } from "./foo.ts"` should be stripped down to `import "./foo.ts"`, but is incorrectly removed outright. EDIT: Occurs in tsc as well.) |
|
@kdy1 A completely unused import is not stripped by swc, but is by tsc. |
Can you check if it works with swc-project/swc#1060 ? Branch lives at https://github.com/kdy1/swc/tree/ts-strip |
The only thing tsc will preserve is a bare import: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I agree with @lucacasonato that we should use this setting at least temporarily to give users more descriptive errors.
@bartlomieju So do we expect this to hit stable before swc-project/swc#1060 lands? As I said, this bug only occurs in the edge case that the user has mistakenly left a completely unused type import. The restrictions it introduces are more than that. The issue with side-effect imports not being left behind (#7413 (comment)) is unrelated. |
@nayeemrmn no, this setting will be default and ignored from |
Run And get error:
There is no error when run |
Yes - this is intentional. See https://deno.land/posts/v1.4#stricter-type-checks-in-code--unstablecode |
In version 1.4 Deno adopted; - the tsconfig setting [importsNotUsedAsValues](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) - denoland/deno#7413 This requires the use of; - type only imports for values which are only used as types (`importsNotUsedAsValues`)
In version 1.4 Deno adopted; - the tsconfig setting [importsNotUsedAsValues](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) - denoland/deno#7413 This requires the use of; - type only imports for values which are only used as types (`importsNotUsedAsValues`)
In version 1.4 Deno adopted; - the tsconfig setting [importsNotUsedAsValues](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) - denoland/deno#7413 This requires the use of; - type only imports for values which are only used as types (`importsNotUsedAsValues`)
In version 1.4 Deno adopted; - the tsconfig setting [importsNotUsedAsValues](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) - denoland/deno#7413 This requires the use of; - type only imports for values which are only used as types (`importsNotUsedAsValues`)
In version 1.4 Deno adopted; - the tsconfig setting [importsNotUsedAsValues](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) - denoland/deno#7413 - the tsconfig setting [isolatedModules](https://www.typescriptlang.org/tsconfig#isolatedModules) when using the deno `--unstable` flag - denoland/deno#7326 ([intended to be enabled by default in 1.5](denoland/deno#7326)) These require the use of; - type only imports for values which are only used as types (`importsNotUsedAsValues`) - type only exports for types which are re-exported (`isolatedModules`) Co-authored-by: Benjamin E. Coe <[email protected]>
…oland#7413)" This reverts commit fbb18d4.
…land#7413" (denoland#7800) This reverts commit fbb18d4.
…land#7413" (denoland#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
…land/deno#7413" (denoland/deno#7800) This reverts commit fbb18d4.
It seems that
"isolatedModules": true
does not catch all errors that can occur with a--nocheck
emit. It looks like"importsNotUsedAsValues": "error"
is also needed becauseisolatedModules
does not catchimport { MyType } from "./file.ts";
, only type re-exports.cc @kitsonk