-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Support class auto import with its type #439
Labels
enhancement
New feature or request
Comments
我也遇到了相同的问题,现在有解决方案吗? |
My solution using // Api.ts
export class Api {
...
}
// auto-imports.d.ts
declare global {
...
const Api: typeof import('./src/apis/Api')['Api']
}
// other file
let someApi: InstanceType<typeof Api> = new Api()
// or
type ApiType = InstanceType<typeof Api>
let someApi: ApiType = new Api()
function myFunc(api: ApiType) {
...
} |
我也有这个问题, 当我使用导入 threejs 中的部分类的时候会报这个错, 如果不加 type, 那就是导入的类, 如果加上 type, 那就是导入的类型, 希望能有个参数控制两者都能使用 AutoImport({
imports: [
{
from: 'three',
imports: ['Group'],
// type: true
}
]
} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clear and concise description of the problem
If declare and export a class.
While directly use it for construct a new instance. Yeah it works properly.
However if use this class for type hint, TypeScript will not recognize it.
typeof Foo
will be the type of Foo's constructor, that isnew () => Foo
, like StringConstructor of String;You have to import that class explicitly, then it will work.
Suggested solution
Do not use
typeof import(xxx)
in the auto-imports.d.ts, useexport xxx from
instead. Just like it in latest Nuxt auto import method.change to
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: