chore: prefer type imports#5835
Conversation
|
FYI: with typescript |
I know, but not sure right now if this is necessary + if the lint rule support it already. |
ok, here the link: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-rc/#type-on-import-names |
| import { resolveServerOptions } from './server' | ||
| import type { ResolvedPreviewOptions, PreviewOptions } from './preview' | ||
| import { resolvePreviewOptions } from './preview' | ||
| import type { CSSOptions } from './plugins/css' |
There was a problem hiding this comment.
What's the benefit of forcing this tho?
To me, it was mainly to avoid accidentally introducing side-effects from the modules that you only need the types from. But if you are already imported some runtime from a module, the type specifier kinda lost the advantage.
I guess the new syntax in 4.5 will be better, but currently, it breaks many imports from one line to two, which kinda makes the code harder to read and maintain to me.
There was a problem hiding this comment.
Yes you are right that the TS 4.5 syntax could help, BUT I would like to use eslint fixer for that
The two lines are sometimes better cause they are then not wrapped cause of printWidth
Also the imports at the top are mostly not for read but auto organized
When TS 4.5 syntax is supported by @typescript-eslint we can switch to the option
There was a problem hiding this comment.
There was a problem hiding this comment.
e6cd16c to
90310b3
Compare
|
TS keeps complaining about Why was I linked here from #6194? What is the solve in vite2? |
|
Was only able to solve with https://vitejs.dev/guide/env-and-mode.html#intellisense-for-typescript This could not be harder to find and does not explain well what the needs are. I dont even know what Intellisense is but I know I'm using TS. |
|
Here's what's happening: By default when you use Here's the original: https://github.com/vitejs/vite/blob/main/packages/create-vite/template-vanilla-ts/src/vite-env.d.ts Alternatively you can fix it by adding {
"compilerOptions": {
"types": ["vite/client"],
}
}Make sure to leave any additional For the {
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["vite/client"],
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}If you've never used Vite before it's a very simple mistake to make, a lot of people seem to have the issue, and all of the issues seem to point to here. Sorry for updating a dead post, closing resolved tickets sucks and results in information going in weird spots when they could instead go into the ticket that shows up on your first Google search. |
Description
Prefer type imports
Additional context
This forces to use always type imports. This improves TS compiled output and removes (in some cases) unnecessary empty imports.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).