【发布时间】:2020-02-18 23:40:59
【问题描述】:
我在一个名为 get() 的类中有一个方法
import optionsInst from "./options";
get(url, opt: optionsInst){}
optionsInst 是另一个文件的接口
export interface Options {
tipoRespuesta?: "json" | "arrayBuffer";
params?: string;
data?: string;
headers?: HeadersInit;
}
export default Options;
我的 tsconfig 是:
{
"compilerOptions": {
"target": "es6",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./dist",
"module": "CommonJS",
"declaration": true,
"allowJs": true
},
"exclude": ["node_modules"]
}
转译我使用npm run build 并生成一个 dist 文件夹。
为了测试它,我创建了一个新文件并运行npm test.js
var CL = require("../dist/index.js");
let instancia = new CL("https://reqres.in/api/");
instancia.get("users").then(console.log);
错误是这样的:
if (utils.isEmpty(opt.headers)) {
^
TypeError: Cannot read property 'headers' of undefined
【问题讨论】:
标签: javascript typescript interface transpiler