type-fest README

The project's README from github.com/sindresorhus/type-fest. As one markdown file: README.md.



type-fest

A collection of essential TypeScript types




Sindre Sorhus' open source work is supported by the community

Special thanks to:

nitric logo
Effortless backends with infrastructure from code
An open-source framework that supports any programming language, cloud provider, or deployment automation tool.





npm dependents npm downloads

Many of the types here should have been built-in. You can help by suggesting some of them to the TypeScript project.

Either add this package as a dependency or copy-paste the needed types. No credit required. 👌

PR welcome for additional commonly needed types and docs improvements. Read the contributing guidelines first.

Help wanted with reviewing proposals and pull requests.

Install

npm install type-fest

Requires TypeScript >=5.9, ESM, and {strict: true} in your tsconfig.

[!NOTE] This readme shows the current development version. For docs about the latest version, see the npm page.

You may also like my ts-extras package which provides runtime functions for some of these types.

Usage

import type {Except} from 'type-fest';

type Foo = {
	unicorn: string;
	rainbow: boolean;
};

type FooWithoutRainbow = Except<Foo, 'rainbow'>;
//=> {unicorn: string}

API

Click the type names for complete docs.

Basic

Utilities

Type Guard

type-fest (sindresorhus/type-fest)

Searching Database…

17.5K ·GitHub
这是干什么的?type-fest 是一套实用的 TypeScript 类型合集——作者认为这些辅助类型本应内置在语言里,涵盖对象、联合类型、字符串、数组、元组和函数。
它是运行时库,还是只有类型定义?只有类型——也就是编译器在构建阶段使用的类型定义,不会在你的应用里执行任何代码。如果需要运行时函数,作者另外发布了一个配套包 ts-extras。
我怎么把它加到项目里?用 npm install type-fest 把它装成依赖,然后导入你需要的类型——或者干脆不装这个包,直接把你想要的那几条定义复制粘贴过去也行。
我的项目对 TypeScript 配置有要求吗?有——需要 TypeScript 5.9 或更新版本、ESM,以及 tsconfig 里开启严格模式({strict: true});较旧的或未开严格模式的代码库用不了它。另外,GitHub 上的 README 写的是尚未发布的开发版内容,正式版本的文档请看 npm。
它都包含哪些类型的类型?远超一百个,分三组:基础类(Primitive、Class、TypedArray)、工具类(Except、Merge、LiteralUnion、PartialDeep、Get……)和类型守卫类(If、IsLiteral、IsNumericLiteral)。
哪些类型值得先了解?Except 可以从对象类型中剔除指定的键,Merge 可以合并两个类型,LiteralUnion 能让字面量联合类型在 IDE 里保留自动补全,Get 则像 Lodash 的 .get() 那样取嵌套属性的类型。
如果我把类型复制粘贴到自己的代码里,需要署名作者吗?不用——type-fest 采用 CC0-1.0 许可证,实际上属于公共领域,README 也说明复制粘贴所需的类型无需署名。
它能跟上 TypeScript 的新版本吗?应该可以:这个仓库的 CI 里包含一个 canary 工作流,会用尚未发布的 TypeScript 构建做测试;README 还鼓励大家把值得纳入语言本身的类型建议提交给 TypeScript 官方项目。
Size
4.2 MB
Stars
17.5K
Age
7y
Commits · 90 Days