DefinitelyTyped /DefinitelyTyped
The repository for high quality TypeScript type definitions.
★ 51,467⑂ 30,310👁 645⑃ 64,373● 8,124▤ 1◈ 3,357
51,467
stars
+-4
30,310
forks
645
watchers
64,373
prs
8,124
issues
1
releases
3,357
discussions
README
Definitely Typed 提供_高质量_ TypeScript 类型定义的仓库。 _你也可以阅读此 README 文件的英语、西班牙语、韩语、俄罗斯语、葡萄牙语、意大利语或日语版本!_ _管理员手册_ !!!重要提示!此仓库最近已更改布局!!!! Definitely Typed 最近已转为正确的 pnpm monorepo(包含多项目或模块);你可能需要重新阅读此文档,以了解此仓库中包的布局更改。 至少,你可能需要执行 git clean -fdx 指令(在 Windows 上为 node ./scripts/clean-node-modules.js)清理仓库以清理 node_modules,然后运行 pnpm install --filter . 以安装工作区根目录。有关 pnpm install 的更多信息,请参见后续章节。 当前状态 此章节跟踪了当前仓库及发布流程的健康状况。如果贡献者的 PR 和软件包遇到任何问题,此处的内容可能有帮助。 - 最新构建全部通过类型检查/Lint: - 所有软件包在 typescript@next 版本中全部通过类型检查/Lint: - 所有软件包都在一个半小时内发布至 npm: - typescript-bot 在 Definitely Typed 上处于活动状态: - 基础设施更新现状 如果此处有任何错误或上述任何操作失败,请在 TypeScript 社群 Discord 服务器中的 Definitely Typed 频道提出。 声明文件是什么,我如何获取它们? 你可以查看 TypeScript 手册。 npm 首选方式是使用 npm 获取声明文件。例如: sh npm install --save-dev @types/node 编译器会自动引入这些类型。 如果你的项目没有使用模块系统,你可能需要手动添加 types 引用: ts /// 更多信息请参见手册。 例如,若 npm 软件包名为“foo”,其类型声明的包名应为“@types/foo”。 如果你的软件包使用 package.json 中的 types 或 typings 关键字指定了类型,那么 npm 注册表就会像这样显示该软件包有可用的绑定: !image 如果还是找不到类型,只需查找软件包中的任何".d.ts "文件,然后用 /// 手动将其包含在内即可 支持周期 Definitely Typed 仅在发布时间小于 2 年的 TypeScript 版本上测试软件包。 旧版本的 TypeScript @types 软件包在标签种列出了其明确支持的 TypeScript 版本,因此你常常可以取得大于 2 年支持周期的软件包旧版本。 例如,若运行 npm dist-tags @types/react,你将看到 TypeScript 2.5 可使用 [email protected] 的类型定义,而 TypeScript 2.6 和 2.7 则可使用 [email protected]: | 标签 | 版本 | | ------ | ------- | | latest | 16.9.23 | | ts2.0 | 15.0.1 | | ... | ... | | ts2.5 | 16.0.36 | | ts2.6 | 16.4.7 | | ts2.7 | 16.4.7 | | ... | ... | TypeScript 1. - 从本仓库的 master 分支手动下载并将其放入你的项目中; - ~~Typings;~~ (请使用首选替代方案,typings 已经被弃用) - ~~NuGet。~~ (请使用首选替代方案,NuGet DT 类型发布已关闭) 你可能需要手动添加引用。 我该如何贡献? Definitely Typed 因来自阁下及众多用户的贡献而发光发热! 测试 在向大众分享你的改进前,请在你的项目中创建名为 typename.d.ts 的文件,并填写其导出以试用你编写的类型声明: ts declare module "libname" { // 类型放置于此处 export function helloWorldMessage(): string; } 测试对现有软件包的修改 你可直接编辑 node_modules/@types/foo/index.d.ts 来验证你的修改。接着,请使用下文所述的步骤将这些修改加入本仓库。 你亦可以使用模块扩充(Module Augmentation来向 Definitely Typed 模块中添加类型,或使用上文所示的 declare module 方法来覆盖 node_modules 中的版本。 为新增的软件包添加测试 在你的 tsconfig.json 中添加以下内容: json "baseUrl": "types", "typeRoots": ["types"], 接下来,请创建 types/foo/index.d.ts 文件,其中包含模块“foo”的类型声明。 现在,你应该能够在代码中导入 "foo" 中的内容,其会自动连接到新增的类型声明。 然后,请构建并运行代码,以确保你的类型声明与运行时发生的情况一致。 一旦你的类型定义在实战中通过测试,请发起拉取请求(Pull request), 然后按照下方的说明编辑现有软件包或创建新软件包。 发起拉取请求(Pull request) 一旦你的软件包通过测试,你便可以在 Definitely Typed 分享它。 首先,复刻(fork)并克隆此仓库, 然后安装 Node,并运行此命令:pnpm install。请注意,pnpm install 将安装整个仓库,包括你可能不需要编辑的包。 如果你只想安装部分内容,可以运行 pnpm install -w --filter "{./types/foo}..." 以安装 @types/foo 及其所有依赖项。 如果你需要运行依赖于 @types/foo 的包的测试,可以运行 pnpm install -w --filter "...{./types/foo}..." 来引入所有相关的测试包。 [!NOTE] 如果你使用的是 Windows,你可能会发现 git clean 不会移除 node_modules 目录,或者在尝试移除时挂起。如果你需要移除 node_modules,你可以运行 pnpm clean-node-modules 来重置仓库。 我们使用机器人来确保能像自助服务一样处理提交至 Definitely Typed 的大量拉取请求。欲知详情,请阅读此处。下图简要展示了拉取请求的生命周期: 部分克隆 你可照常克隆本仓库,但本仓库极为庞大,包含海量的类型声明包。 你可照常克隆本仓库,但本仓库极为庞大,包含海量的类型声明包。因此,克隆操作将会耗费大量时间,显得笨拙且毫无必要。 你可以使用 git 的 sparse-ch
Top issues
#31245[styled-component] Support css prop56 comments · 2018-12-10#59765@types/react@18 break @types/styled-components42 comments · 2022-04-08#47780Express' has no exported member 'Multer'42 comments · 2020-09-18#33290Installing @types/mongoose breaks the compiler32 comments · 2019-02-21#16208@types/react-bootstrap form event typings are unusable32 comments · 2017-04-28#49595[@types/express] Namespace 'serveStatic' has no exported member 'RequestHandlerConstructor'27 comments · 2020-11-16#50200[@types/lodash-es] no exported member DebouncedFunc25 comments · 2020-12-20#26847DefinitelyTyped repo overhaul - docs/automatisation/formatting25 comments · 2018-06-26
Discussions
#76117[@types/vue2-editor] The default export is typed as the VueEditor component, but it is the plugin, so `Vue.use` on it does not type-check2 comments · 2026-11-06#76116[@types/node] TS2502 in global crypto with 26.6.6, Deno 2.9.8 and TypeScript 61 comments · 2026-11-06#76103[@types/node] Missing `QuicStream.writer` in Node.js v24 QUIC API typings2 comments · 2026-11-04#75867[@types/node] SQLite’s classes changed name2 comments · 2026-10-28#75838"No overload matches this call" for `assert()` in [node] since v263 comments · 2026-10-24#75834[@types/html-to-pdfmake] `window` requires jsdom's `DOMWindow`, pins `@types/pdfmake` to 0.2, and types `showHidden` as `showhidden`1 comments · 2026-10-23#75802[react] TouchList.item should be able to return null3 comments · 2026-10-21#75752[@types/sinon] has incorrect types for useFakeTimers function. [@types/sinon__fake-timers] should be deprecated.2 comments · 2026-10-09