typescript - 为可调用模块编写 TypeScript 声明文件

标签 typescript type-declaration cldr

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());

关于typescript - 为可调用模块编写 TypeScript 声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69918770/

相关文章:

c++ - c++ 是否提供了一种使整个结构常量(不可修改)的方法?

json - 错误搜寻 : CLDR 30 JSON data no longer has currencySpacing information

javascript - 粗略的 Unicode -> 没有 CLDR 的语言代码?

javascript - 如何在 React Native 中使用 Jest 测试 lodash 的去抖功能?

go - 声明函数类型的方法有什么区别?

haskell - 如何与外部上下文中的类型相关联

reactjs - 将 TypeScript 与 React、无状态组件结合使用

javascript - 如何格式化仅包含日和月的给定日期?

javascript - 使用 WebWorker 时,从导入其他类的文件中导入类会导致 Angular 8 编译失败