我很可能在这里丢失了一些tsconfig选项。在模块中自动换行手稿定义文件
什么IM做的是非常简单的:
我创建一个新公共管理模块,例如:
export class HelloWorld {
constructor(public greeting: string){}
}
我tsconfig之中:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"removeComments": true,
"noImplicitAny": false,
"preserveConstEnums": true,
"declaration": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "../js"
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
]
}
时会自动创建我的声明它看起来像这样:
export declare class HelloWorld {
greeting: string;
constructor(greeting: string);
}
但是,实际上在其他项目中安装npm软件包时,这种方法效果不佳。当我导入包我必须使用:
import hello = require("hello-world/js/index");
(例如)
我发现,当我包裹声明文件中模块declare module "hello-world" {...}
由import hello = require("hello-world");
手动包装生成的定义文件不是一个选项,因为它会一直重写自己,是否有任何选项会从package.json
中获取包的名称并自动将定义包装在该模块中?
你尝试“出口默认类的HelloWorld”? – baryo
@baryo是没有任何区别 – Tom
可以请你发布你的package.json吗? – baryo