我有一个typescript+javascript模块,它被编译成一个包,可以由另一个项目导入。我想最好用一些代码来解释,然后再解释我的问题。
需要用作类型的类:
我的-类.ts
export default class MyClass{
...
}
import MyClass from './my-class';
export {
MyClass,
};
索引d.ts
declare module '@package/my-project'{
export interface MyClass{
//Am I supposed to declares types here?
}
}
import {MyClass} from '@package/my-project';
private myClassInstance: any; //I want this to be :MyClass instead of "any"
beforeCreate(){
this.myClassInstance = new MyClass();
}
我一直在看下面的链接,但是,真的不知道如何实现这一点。
https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html
https://github.com/benjamn/ast-types/issues/106
https://medium.com/@tomsoir/typescript-how-to-rewrite-type-definition-file-file-d-ts-of-any-node-modules-package-1eed7f5630d1
给一些背景,这里是我的tsconfig.json文件文件:
{
"extends": "./extradetails.json",
"compilerOptions": {
"allowJs": true,
"declaration": false,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": false
}
}