假设我有一个发布到NPM的lib,只有一行:
var change = prompt("Enter 1 or 2");
if (change === '1') {
document.getElementById("change").innerHTML = "You said one!";
}
else if (change === '2') {
document.getElementById("change").innerHTML = "You said two!";
}
else {
document.getElementById("change").innerHTML = "That was not an option.";
}
想要将其导入此回购邮件的// file name index.js
function myLib(x) {return x;}
https://github.com/AngularClass/angular2-webpack-starter/blob/master/src/app/app.component.ts
app.component.ts
之后,将npm install myLib
文件创建为index.d.ts
node_modules/myLib/
以下是我的问题:
问题1.在export default function myLib (x: any): any;
// or
// declare function myLib (x: any): any;
// export default myLib;
中将其视为:
app.component.ts
结果是import myLib from 'myLib'
console.log( myLib )
,为什么?
问2.如果更改代码如下:
undefined
结果是import * as myLib from 'myLib'
console.log( myLib )
,似乎是对的,但是
function myLib(x) {return x;}
Webpack显示错误消息:
的src /应用/ app.component.ts:12:21
无法调用类型缺少调用签名的表达式
到底是什么?
谢谢!