为可调用模块编写 TypeScript 声明文件
Write TypeScript declaration file for callable module
cldr-data
包定义如下:
function cldrData(path) {
// ...
}
cldrData.all = function() {
// ...
}
cldrData.entireMainFor = function(locale/*, ...*/) {
// ...
}
cldrData.entireSupplemental = function() {
// ...
}
module.exports = cldrData;
这样的包应该怎么写类型声明文件?
这似乎有效:
declare module 'cldr-data' {
interface CldrData {
(path: any, ...args: any[]): any;
availableLocales: any;
all(): any;
entireMainFor(locale: any, ...args: any[]): any;
entireSupplemental(): any;
}
declare const cldrData: CldrData;
export = cldrData;
};
用法:
import cldrData from 'cldr-data';
cldrData('main/en/numbers');
cldrData.entireSupplemental();
cldrData.entireMainFor('en');
console.log(cldrData.all());
cldr-data
包定义如下:
function cldrData(path) {
// ...
}
cldrData.all = function() {
// ...
}
cldrData.entireMainFor = function(locale/*, ...*/) {
// ...
}
cldrData.entireSupplemental = function() {
// ...
}
module.exports = cldrData;
这样的包应该怎么写类型声明文件?
这似乎有效:
declare module 'cldr-data' {
interface CldrData {
(path: any, ...args: any[]): any;
availableLocales: any;
all(): any;
entireMainFor(locale: any, ...args: any[]): any;
entireSupplemental(): any;
}
declare const cldrData: CldrData;
export = cldrData;
};
用法:
import cldrData from 'cldr-data';
cldrData('main/en/numbers');
cldrData.entireSupplemental();
cldrData.entireMainFor('en');
console.log(cldrData.all());