2

包的cldr-data定义如下:

function cldrData(path) {
  // ...
}

cldrData.all = function() {
  // ...
}

cldrData.entireMainFor = function(locale/*, ...*/) {
  // ...
}

cldrData.entireSupplemental = function() {
  // ...
}

module.exports = cldrData;

我应该如何为这样的包编写类型声明文件?

4

1 回答 1

2

这似乎有效:

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());
于 2021-11-10T19:32:27.900 回答