17,498
stars
+9+11+61
746
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions
README
A collection of essential TypeScript types
Sindre Sorhus' open source work is supported by the community
Special thanks to:
Effortless backends with infrastructure from code
An open-source framework that supports any programming language, cloud provider, or deployment automation tool.
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
sh
npm install type-fest
Requires TypeScript =6, ESM, and {strict: true} in your tsconfig.
{exactOptionalPropertyTypes: true} is required. Disabling it is unsupported.
[!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
ts
import type {Except} from 'type-fest';
type Foo = {
unicorn: string;
rainbow: boolean;
};
type FooWithoutRainbow = Except;
//= {unicorn: string}
Try it in the TypeScript Playground
API
Click the type names for complete docs.
Basic
- Primitive - Matches any primitive value.
- Class - Matches a class.
- Constructor - Matches a class constructor.
- AbstractClass - Matches an abstract class.
- AbstractConstructor - Matches an abstract class constructor.
- AsyncFunction - Matches an asynchronous function.
- AnyAsyncFunction - Matches any asynchronous function.
- AnyFunction - Matches any function.
- TypedArray - Matches any typed array, like Uint8Array or Float64Array.
- ReadonlyDate - Matches a Date that cannot be changed.
- ObservableLike - Matches a value that is like an Observable.
- LowercaseLetter - Matches any lowercase letter in the basic Latin alphabet (a-z).
- UppercaseLetter - Matches any uppercase letter in the basic Latin alphabet (A-Z).
- DigitCharacter - Matches any digit as a string ('0'-'9').
- Alphanumeric - Matches any lowercase letter (a-z), uppercase letter (A-Z), or digit ('0'-'9') in the basic Latin alphabet.
Utilities
- EmptyObject - Represents a strictly empty plain object, the {} value.
- NonEmptyObject - Represents an object with at least 1 non-optional key.
- UnknownRecord - Represents an object with unknown value. You probably want this instead of {}.
- UnknownArray - Represents an array with unknown value.
- UnknownMap - Represents a map with unknown key and value.
- UnknownSet - Represents a set with unknown value.
- Except - Create a type from an object type without certain keys.
- Writable - Create a type that strips readonly from the given type. Inverse of Readonly.
- WritableDeep - Create a deeply mutable version of an object/ReadonlyMap/Read