【问题标题】:How do I make my declaration files for the typescript library available for install at @types/mylibrary如何使我的 typescript 库的声明文件可以安装在 @types/mylibrary
【发布时间】:2020-07-20 23:31:07
【问题描述】:

我已经创建了我的库并将其发布到 npm 并且工作正常。问题是我无法在我的编辑器(与代码)上获得智能。将声明文件手动放在 node_modules/@types 完美运行。我希望我的类型可以使用 npm i @types/mylibrary 在 npm 上下载。

在我的搜索中,我遇到了这个https://github.com/DefinitelyTyped/DefinitelyTyped,它需要提取所有可用类型并为新类型发送 PR。

有没有简单的存档方法?

【问题讨论】:

    标签: javascript typescript types typescript-typings type-declaration


    【解决方案1】:

    我认为没有必要。

    您当前的ts.config 是否已经生成类型?

    只需将types 添加到您的package.config,例如:

    {
        "main": "dist/index.js",
        "types": "dist/index.d.ts",
        ...
    }
    

    (假设 outDir 是/dist/

    【讨论】:

    • 你能在这个库是依赖的项目中看到node_modules中的d.ts文件吗?
    • 如果你写import * as x from '<your-lib>';,然后输入x.,然后按ctrl+空格?
    猜你喜欢
    • 2018-04-28
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2017-07-03
    相关资源
    最近更新 更多