We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
If declare and export a class.
export default class Foo { }
While directly use it for construct a new instance. Yeah it works properly.
const foo = new Foo();
However if use this class for type hint, TypeScript will not recognize it.
const foo: Foo = new Foo(); ^^^ function myFunc(foo: Foo) { ^^^ }
Error: 'Foo' refers to a value, but is being used as a type here. Did you mean 'typeof Foo'?
typeof Foo will be the type of Foo's constructor, that is new () => Foo, like StringConstructor of String;
typeof Foo
new () => Foo
You have to import that class explicitly, then it will work.
import type Foo from "../classes/Foo";
Do not use typeof import(xxx) in the auto-imports.d.ts, use export xxx from instead. Just like it in latest Nuxt auto import method.
typeof import(xxx)
export xxx from
const Foo: typeof import('../classes/Foo')['default'];
change to
export Foo from '../classes/Foo';
No response
The text was updated successfully, but these errors were encountered:
我也遇到了相同的问题,现在有解决方案吗? I ran into the same problem, is there a solution now?
Sorry, something went wrong.
My solution using InstanceType:
InstanceType
// 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 } ] } )
No branches or pull requests
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: