我很可能在這裏丟失了一些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