typescriptプロジェクト内で小さなjavascriptライブラリを使用したいと思います。 (full example see hereの場合)。Typescriptを使用したデフォルトエクスポートの使用
JavaScriptライブラリは、次のように定義しています
"use strict";
exports.__esModule = true;
exports["default"] = functionOfInterest;
function functionOfInterest(val) { }
module.exports = exports["default"];
これはとして.d.ts
ファイルを使用してタイプされています
import functionOfInterest from "the-package";
functionOfInterest(1); // invoke it.
この:私が使用typescriptファイルで
export default function functionOfInterest(val: number): void;
コンパイルされます:
の"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var functionOfInterest_1 = require("the-package");
functionOfInterest_1.default.apply(void 0, 1);
このエラー:
TypeError: Cannot read property 'apply' of undefined
私tsconfig.json
ファイルは次のとおりです。
{
"compilerOptions": {
"outDir": "js",
"module": "commonjs",
"declaration": true,
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "ts",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
},
"exclude": [
"node_modules",
"build"
]
}
私はどこかに単純な構成エラーがあります確信しているが、私は、現時点ではそれを把握することはできません。
あなたが使用する必要が活字体2.2.2
、このエラーを。 [ts] 'from'は予想通りです。任意の – AJP