0
我想爲random-string寫一個.d.ts。隨機串模塊的類型定義異常
我有這樣的代碼:
declare module "random-string" {
export function randomString(opts?: Object): string;
}
我能夠導入模塊沒有問題,然後用:
import randomString = require('random-string');
和調用:
console.log(randomString); // --> [Function: randomString]
然而,這並未」不管參與或不參與:
console.log(randomString({length: 10});
console.log(randomString());
我得到這個錯誤從TSC:
錯誤TS2088:無法調用其類型缺乏調用簽名的表達式。
我看着在源隨機字符串,並發現此代碼爲方法,我試圖用接口:
module.exports = function randomString(opts) {
// Implementation...
};
我設法寫.d.ts爲CSON模塊,沒問題,但那是直接導出'類'而不是函數。這很重要嗎?
這很好。謝謝。 –