Update for 2024: do whatever you want 🙃
Do not use `import type` unless you need to.
Community note
This comment was written before TypeScript shipped the `verbatimModuleSyntax` configuration option, which improves upon the behavior of `import type`: typescriptlang.org/tsconfig/#verb… Several experts on TypeScript, including the original author of this comment, no longer stand by this guidance: x.com/atcb/status/17… x.com/mattpocockuk/s…

May 27, 2024 · 1:08 AM UTC

9
48
502
155,098
The problem with type-only imports is that as soon as they existed, everyone became convinced that using them would be the *only* way to drop runtime-unnecessary imports from their output, whether they were using tsc or other tools. This was never true.
1
2
23
5,380
Single-file transpilers were always able to handle 99% of removing imports only used for types with cheap usage analysis. The remaining 1% are isolatedModules errors. For a long time I fought this misconception by saying “you don’t need this, you’re already getting what you want”
1
17
4,927
I like people to know why they’re writing the code they’re writing. But even when I told people it was having no effect on their output, most folks kept using type-only imports as a signal of explicit intent. They just *liked* using them. I now think that’s a fine reason.
2
40
4,542
Early on, I was reluctant to make type-only imports easier to adopt as a wholesale stylistic choice because I thought it would add to the confusion. Eventually, you all changed my mind, and I added a VS Code preference to make auto-imports use them as much as possible.
3
4
39
4,925
I personally tend to use type-only imports via auto-imports (with `verbatimModuleSyntax`) in new projects, but maybe I just like using stuff I made 😄Do what makes you happy, and go deeper into understanding how your tools work if you can. It might be more complex than you think.
1
48
4,063
Sort replies: Relevant Recent Liked
Replying to @atcb
🫡
6
3,461
Replying to @atcb
🫡
1
106
Replying to @atcb
`import foo from "./mod" with { yo: "lo" }`
1
382
Replying to @atcb
Lmaf
650
Replying to @atcb
As a brainless typescript newbie, I do what ESLint tells me to do, and is currently forcing me to use import type
433