-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
RFC: Auto register for types #61
Comments
Created new branch
You can find global types presets stuff on There are some EDIT: maybe there is a breaking change if someone is using the |
Right now I include global types on // Generated by 'unplugin-auto-import'
// We suggest you to commit this file into source control
import type {
ComputedRef as __ComputedRef,
Ref as __Ref
} from 'vue'
declare global {
type ComputedRef<T> = __ComputedRef<T>
type Ref<T> = __Ref<T>
const computed: typeof import('vue')['computed']
...
}
export{} maybe we can use this another approach as suggested on issue on // Generated by 'unplugin-auto-import'
// We suggest you to commit this file into source control
declare global {
type ComputedRef<T> = import('vue').ComputedRef<T>
type Ref<T> = import('vue').Ref<T>
const computed: typeof import('vue')['computed']
...
}
export {} |
Pushed some changes:
|
Will you release a npm package with integrated #118 soon? |
It's not yet possible to have a https://stackblitz.com/edit/node-jjgj6g?file=index.ts I'd consider it as a limitation of TypeScript. If anyone finds a solution, please comment with a fork of the Stackblitz playground and then we could discuss how to implement that. Thanks. |
According to this: https://gist.github.com/Bnaya/97080f563fa8242e26a041732185a260 it depends to some typescript flag that can (and perhaps should) be disabled? |
@antfu Maybe I misunderstood, but is this not what you want?
Both seems to work, at least to my needs:
I'm happy with that. |
也就是说现阶段想使用依赖的interface或其它类型定义(e.g: Ref),依旧需要通过显示引入的方式么🤔️ |
@terran42 Thanks for trying. But your solution seems to throw away the generics and make them |
@antfu TypeScript 5.0 introduces Any chances that type auto-imports could be implemented in the near future after TS 5.0 release? |
dirs 配置的目标文件 中的类型 怎么自动导出 |
现在(截至v0.18.2), 在本地有两种办法
比如使用 pnpm: 在 dist/chunk* 文件中查找 scanExports 方法, 将第二个参数改为 true,
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig(() => {
return {
plugins: [
AutoImport({
imports: [
{
from: resolve(__dirname, 'src/types/memory'),
imports: [
'MemoryItem',
],
type: true,
},
]
})
]
}
}) 第一种方式启用文件夹的类型包含后, 暂不清楚是否有其它副作用, 好处是不用自己枚举了, 只要在放进 dirs 选项就可以; |
Context:
pinia
andvuex
presets #60 (comment)For example, it would be great to have common types like
Ref
,ComputedRef
globally available when using the Vue preset. I would expect the API to be likeThe text was updated successfully, but these errors were encountered: