我与ES6进口语法工作和导入第三方ES5模块谁出口一单出口这是一个匿名函数的打字稿进口:的ES5匿名函数
module.exports = function (phrase, inject, callback) { ... }
因为没有默认的出口,而是一个匿名函数输出我必须导入和使用像这样:
import * as sentiment from 'sentiment';
const analysis = sentiment(content);
这给打字稿错误:
error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof "sentiment"' has no compatible call signatures.
我想我得到的是因为我没有正确输入ES5导入(没有公共打印文件)。回来时,我虽然功能是默认出口我有如下定义:
interface IResults {
Score: number;
Comparitive: number;
}
declare var fn: (contents: string, overRide?: IDictionary<number>) => IResults;
declare module "sentiment" {
export default fn;
};
这一切都感觉良好,但看到的进口是不默认的导出我不知道如何定义这个模块和功能。我曾尝试以下操作:
declare module "sentiment" {
export function (contents: string, overRide?: IDictionary<number>): IResults;
};
,虽然这似乎是一个有效的导出定义并不匿名呼叫定义相符,并引发以下错误:
error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof "sentiment"' has no compatible call signatures.
谢谢,这确实诀窍。 – ken