• Stars
    star
    14,015
  • Rank 2,172 (Top 0.05 %)
  • Language
    TypeScript
  • License
    Creative Commons ...
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of essential TypeScript types


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.1

Works best with {strict: true} in your tsconfig.

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

  • 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.
  • Except - Create a type from an object type without certain keys. This is a stricter version of Omit.
  • Writable - Create a type that strips readonly from the given type. Inverse of Readonly<T>.
  • WritableDeep - Create a deeply mutable version of an object/ReadonlyMap/ReadonlySet/ReadonlyArray type. The inverse of ReadonlyDeep<T>. Use Writable<T> if you only need one level deep.
  • Merge - Merge two types into a new type. Keys of the second type overrides keys of the first type.
  • MergeDeep - Merge two objects or two arrays/tuples recursively into a new type.
  • MergeExclusive - Create a type that has mutually exclusive keys.
  • OverrideProperties - Override only existing properties of the given type. Similar to Merge, but enforces that the original type has the properties you want to override.
  • RequireAtLeastOne - Create a type that requires at least one of the given keys.
  • RequireExactlyOne - Create a type that requires exactly a single key of the given keys and disallows more.
  • RequireAllOrNone - Create a type that requires all of the given keys or none of the given keys.
  • RequireOneOrNone - Create a type that requires exactly a single key of the given keys and disallows more, or none of the given keys.
  • SingleKeyObject - Create a type that only accepts an object with a single key.
  • RequiredDeep - Create a deeply required version of another type. Use Required<T> if you only need one level deep.
  • PickDeep - Pick properties from a deeply-nested object. Use Pick<T> if you only need one level deep.
  • OmitDeep - Omit properties from a deeply-nested object. Use Omit<T> if you only need one level deep.
  • OmitIndexSignature - Omit any index signatures from the given object type, leaving only explicitly defined properties.
  • PickIndexSignature - Pick only index signatures from the given object type, leaving out all explicitly defined properties.
  • PartialDeep - Create a deeply optional version of another type. Use Partial<T> if you only need one level deep.
  • PartialOnUndefinedDeep - Create a deep version of another type where all keys accepting undefined type are set to optional.
  • UndefinedOnPartialDeep - Create a deep version of another type where all optional keys are set to also accept undefined.
  • ReadonlyDeep - Create a deeply immutable version of an object/Map/Set/Array type. Use Readonly<T> if you only need one level deep.
  • LiteralUnion - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for Microsoft/TypeScript#29729.
  • Tagged - Create a tagged type that can support multiple tags if needed.
  • UnwrapTagged - Get the untagged portion of a tagged type created with Tagged.
  • Opaque - Create a tagged type. This implementation only supports a single tag.
  • UnwrapOpaque - Get the untagged portion of a tagged type created with Opaque or Tagged.
  • InvariantOf - Create an invariant type, which is a type that does not accept supertypes and subtypes.
  • SetOptional - Create a type that makes the given keys optional.
  • SetReadonly - Create a type that makes the given keys readonly.
  • SetRequired - Create a type that makes the given keys required.
  • SetNonNullable - Create a type that makes the given keys non-nullable.
  • ValueOf - Create a union of the given object's values, and optionally specify which keys to get the values from.
  • ConditionalKeys - Extract keys from a shape where values extend the given Condition type.
  • ConditionalPick - Like Pick except it selects properties from a shape where the values extend the given Condition type.
  • ConditionalPickDeep - Like ConditionalPick except that it selects the properties deeply.
  • ConditionalExcept - Like Omit except it removes properties from a shape where the values extend the given Condition type.
  • UnionToIntersection - Convert a union type to an intersection type.
  • LiteralToPrimitive - Convert a literal type to the primitive type it belongs to.
  • LiteralToPrimitiveDeep - Like LiteralToPrimitive except it converts literal types inside an object or array deeply.
  • Stringified - Create a type with the keys of the given type changed to string type.
  • IterableElement - Get the element type of an Iterable/AsyncIterable. For example, an array or a generator.
  • Entry - Create a type that represents the type of an entry of a collection.
  • Entries - Create a type that represents the type of the entries of a collection.
  • SetReturnType - Create a function type with a return type of your choice and the same parameters as the given function type.
  • SetParameterType - Create a function that replaces some parameters with the given parameters.
  • Simplify - Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
  • Get - Get a deeply-nested property from an object using a key path, like Lodash's .get() function.
  • StringKeyOf - Get keys of the given type as strings.
  • Schema - Create a deep version of another object type where property values are recursively replaced into a given value type.
  • Exact - Create a type that does not allow extra properties.
  • OptionalKeysOf - Extract all optional keys from the given type.
  • KeysOfUnion - Create a union of all keys from a given type, even those exclusive to specific union members.
  • HasOptionalKeys - Create a true/false type depending on whether the given type has any optional fields.
  • RequiredKeysOf - Extract all required keys from the given type.
  • HasRequiredKeys - Create a true/false type depending on whether the given type has any required fields.
  • ReadonlyKeysOf - Extract all readonly keys from the given type.
  • HasReadonlyKeys - Create a true/false type depending on whether the given type has any readonly fields.
  • WritableKeysOf - Extract all writable (non-readonly) keys from the given type.
  • HasWritableKeys - Create a true/false type depending on whether the given type has any writable fields.
  • Spread - Mimic the type inferred by TypeScript when merging two objects or two arrays/tuples using the spread syntax.
  • IsEqual - Returns a boolean for whether the two given types are equal.
  • TaggedUnion - Create a union of types that share a common discriminant property.
  • IntRange - Generate a union of numbers.
  • ArrayIndices - Provides valid indices for a constant array or tuple.
  • ArrayValues - Provides all values for a constant array or tuple.
  • ArraySplice - Creates a new array type by adding or removing elements at a specified index range in the original array.
  • SetFieldType - Create a type that changes the type of the given keys.
  • Paths - Generate a union of all possible paths to properties in the given object.
  • SharedUnionFieldsDeep - Create a type with shared fields from a union of object types, deeply traversing nested structures.
  • DistributedOmit - Omits keys from a type, distributing the operation over a union.
  • DistributedPick - Picks keys from a type, distributing the operation over a union.

Type Guard

IsType vs. IfType

For every IsT type (e.g. IsAny), there is an associated IfT type that can help simplify conditional types. While the IsT types return a boolean, the IfT types act like an If/Else - they resolve to the given TypeIfT or TypeIfNotT depending on whether IsX is true or not. By default, IfT returns a boolean:

type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
	IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
);

Usage

import type {IsAny, IfAny} from 'type-fest';

type ShouldBeTrue = IsAny<any> extends true ? true : false;
//=> true

type ShouldBeFalse = IfAny<'not any'>;
//=> false

type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
//=> 'never'

JSON

  • Jsonify - Transform a type to one that is assignable to the JsonValue type.
  • Jsonifiable - Matches a value that can be losslessly converted to JSON.
  • JsonPrimitive - Matches a JSON primitive.
  • JsonObject - Matches a JSON object.
  • JsonArray - Matches a JSON array.
  • JsonValue - Matches any valid JSON value.

Async

  • Promisable - Create a type that represents either the value or the value wrapped in PromiseLike.
  • AsyncReturnType - Unwrap the return type of a function that returns a Promise.
  • Asyncify - Create an async version of the given function type.

String

  • Trim - Remove leading and trailing spaces from a string.
  • Split - Represents an array of strings split using a given character or character set.
  • Replace - Represents a string with some or all matches replaced by a replacement.
  • StringSlice - Returns a string slice of a given range, just like String#slice().

Array

  • Includes - Returns a boolean for whether the given array includes the given item.
  • Join - Join an array of strings and/or numbers using the given string as a delimiter.
  • ArraySlice - Returns an array slice of a given range, just like Array#slice().
  • LastArrayElement - Extracts the type of the last element of an array.
  • FixedLengthArray - Create a type that represents an array of the given type and length.
  • MultidimensionalArray - Create a type that represents a multidimensional array of the given type and dimensions.
  • MultidimensionalReadonlyArray - Create a type that represents a multidimensional readonly array of the given type and dimensions.
  • ReadonlyTuple - Create a type that represents a read-only tuple of the given type and length.
  • TupleToUnion - Convert a tuple/array into a union type of its elements.

Numeric

  • PositiveInfinity - Matches the hidden Infinity type.
  • NegativeInfinity - Matches the hidden -Infinity type.
  • Finite - A finite number.
  • Integer - A number that is an integer.
  • Float - A number that is not an integer.
  • NegativeFloat - A negative (-∞ < x < 0) number that is not an integer.
  • Negative - A negative number/bigint (-∞ < x < 0)
  • NonNegative - A non-negative number/bigint (0 <= x < ∞).
  • NegativeInteger - A negative (-∞ < x < 0) number that is an integer.
  • NonNegativeInteger - A non-negative (0 <= x < ∞) number that is an integer.
  • IsNegative - Returns a boolean for whether the given number is a negative number.
  • IsFloat - Returns a boolean for whether the given number is a float, like 1.5 or -1.5.
  • IsInteger - Returns a boolean for whether the given number is a integer, like -5, 1.0 or 100.
  • GreaterThan - Returns a boolean for whether a given number is greater than another number.
  • GreaterThanOrEqual - Returns a boolean for whether a given number is greater than or equal to another number.
  • LessThan - Returns a boolean for whether a given number is less than another number.
  • LessThanOrEqual - Returns a boolean for whether a given number is less than or equal to another number.
  • Sum - Returns the sum of two numbers.
  • Subtract - Returns the difference between two numbers.

Change case

Miscellaneous

Declined types

If we decline a type addition, we will make sure to document the better solution here.

  • Diff and Spread - The pull request author didn't provide any real-world use-cases and the PR went stale. If you think this type is useful, provide some real-world use-cases and we might reconsider.
  • Dictionary - You only save a few characters (Dictionary<number> vs Record<string, number>) from Record, which is more flexible and well-known. Also, you shouldn't use an object as a dictionary. We have Map in JavaScript now.
  • ExtractProperties and ExtractMethods - The types violate the single responsibility principle. Instead, refine your types into more granular type hierarchies.
  • Url2Json - Inferring search parameters from a URL string is a cute idea, but not very useful in practice, since search parameters are usually dynamic and defined separately.
  • Nullish - The type only saves a couple of characters, not everyone knows what "nullish" means, and I'm also trying to get away from null.
  • TitleCase - It's not solving a common need and is a better fit for a separate package.
  • ExtendOr and ExtendAnd - The benefits don't outweigh having to learn what they mean.
  • PackageJsonExtras - There are too many possible configurations that can be put into package.json. If you would like to extend PackageJson to support an additional configuration in your project, please see the Extending existing types section below.

Alternative type names

If you know one of our types by a different name, add it here for discovery.

Tips

Extending existing types

  • PackageJson - There are a lot of tools that place extra configurations inside the package.json file. You can extend PackageJson to support these additional configurations.

    Example

    Playground

     import type {PackageJson as BasePackageJson} from 'type-fest';
     import type {Linter} from 'eslint';
    
     type PackageJson = BasePackageJson & {eslintConfig?: Linter.Config};

Related

Built-in types

There are many advanced types most users don't know about.

  • Partial<T> - Make all properties in T optional.

    Example

    Playground

     interface NodeConfig {
     		appName: string;
     		port: number;
     }
    
     class NodeAppBuilder {
     		private configuration: NodeConfig = {
     				appName: 'NodeApp',
     				port: 3000
     		};
    
     		private updateConfig<Key extends keyof NodeConfig>(key: Key, value: NodeConfig[Key]) {
     				this.configuration[key] = value;
     		}
    
     		config(config: Partial<NodeConfig>) {
     				type NodeConfigKey = keyof NodeConfig;
    
     				for (const key of Object.keys(config) as NodeConfigKey[]) {
     						const updateValue = config[key];
    
     						if (updateValue === undefined) {
     								continue;
     						}
    
     						this.updateConfig(key, updateValue);
     				}
    
     				return this;
     		}
     }
    
     // `Partial<NodeConfig>`` allows us to provide only a part of the
     // NodeConfig interface.
     new NodeAppBuilder().config({appName: 'ToDoApp'});
  • Required<T> - Make all properties in T required.

    Example

    Playground

     interface ContactForm {
     		email?: string;
     		message?: string;
     }
    
     function submitContactForm(formData: Required<ContactForm>) {
     		// Send the form data to the server.
     }
    
     submitContactForm({
     		email: '[email protected]',
     		message: 'Hi! Could you tell me more about…',
     });
    
     // TypeScript error: missing property 'message'
     submitContactForm({
     		email: '[email protected]',
     });
  • Readonly<T> - Make all properties in T readonly.

    Example

    Playground

     enum LogLevel {
     		Off,
     		Debug,
     		Error,
     		Fatal
     };
    
     interface LoggerConfig {
     		name: string;
     		level: LogLevel;
     }
    
     class Logger {
     		config: Readonly<LoggerConfig>;
    
     		constructor({name, level}: LoggerConfig) {
     				this.config = {name, level};
     				Object.freeze(this.config);
     		}
     }
    
     const config: LoggerConfig = {
     	name: 'MyApp',
     	level: LogLevel.Debug
     };
    
     const logger = new Logger(config);
    
     // TypeScript Error: cannot assign to read-only property.
     logger.config.level = LogLevel.Error;
    
     // We are able to edit config variable as we please.
     config.level = LogLevel.Error;
  • Pick<T, K> - From T, pick a set of properties whose keys are in the union K.

    Example

    Playground

     interface Article {
     		title: string;
     		thumbnail: string;
     		content: string;
     }
    
     // Creates new type out of the `Article` interface composed
     // from the Articles' two properties: `title` and `thumbnail`.
     // `ArticlePreview = {title: string; thumbnail: string}`
     type ArticlePreview = Pick<Article, 'title' | 'thumbnail'>;
    
     // Render a list of articles using only title and description.
     function renderArticlePreviews(previews: ArticlePreview[]): HTMLElement {
     		const articles = document.createElement('div');
    
     		for (const preview of previews) {
     				// Append preview to the articles.
     		}
    
     		return articles;
     }
    
     const articles = renderArticlePreviews([
     		{
     			title: 'TypeScript tutorial!',
     			thumbnail: '/assets/ts.jpg'
     		}
     ]);
  • Record<K, T> - Construct a type with a set of properties K of type T.

    Example

    Playground

     // Positions of employees in our company.
     type MemberPosition = 'intern' | 'developer' | 'tech-lead';
    
     // Interface describing properties of a single employee.
     interface Employee {
     		firstName: string;
     		lastName: string;
     		yearsOfExperience: number;
     }
    
     // Create an object that has all possible `MemberPosition` values set as keys.
     // Those keys will store a collection of Employees of the same position.
     const team: Record<MemberPosition, Employee[]> = {
     		intern: [],
     		developer: [],
     		'tech-lead': [],
     };
    
     // Our team has decided to help John with his dream of becoming Software Developer.
     team.intern.push({
     	firstName: 'John',
     	lastName: 'Doe',
     	yearsOfExperience: 0
     });
    
     // `Record` forces you to initialize all of the property keys.
     // TypeScript Error: "tech-lead" property is missing
     const teamEmpty: Record<MemberPosition, null> = {
     		intern: null,
     		developer: null,
     };
  • Exclude<T, U> - Exclude from T those types that are assignable to U.

    Example

    Playground

     interface ServerConfig {
     	port: null | string | number;
     }
    
     type RequestHandler = (request: Request, response: Response) => void;
    
     // Exclude `null` type from `null | string | number`.
     // In case the port is equal to `null`, we will use default value.
     function getPortValue(port: Exclude<ServerConfig['port'], null>): number {
     	if (typeof port === 'string') {
     		return parseInt(port, 10);
     	}
    
     	return port;
     }
    
     function startServer(handler: RequestHandler, config: ServerConfig): void {
     	const server = require('http').createServer(handler);
    
     	const port = config.port === null ? 3000 : getPortValue(config.port);
     	server.listen(port);
     }
  • Extract<T, U> - Extract from T those types that are assignable to U.

    Example

    Playground

     declare function uniqueId(): number;
    
     const ID = Symbol('ID');
    
     interface Person {
     	[ID]: number;
     	name: string;
     	age: number;
     }
    
     // Allows changing the person data as long as the property key is of string type.
     function changePersonData<
     	Obj extends Person,
     	Key extends Extract<keyof Person, string>,
     	Value extends Obj[Key]
     > (obj: Obj, key: Key, value: Value): void {
     	obj[key] = value;
     }
    
     // Tiny Andrew was born.
     const andrew = {
     	[ID]: uniqueId(),
     	name: 'Andrew',
     	age: 0,
     };
    
     // Cool, we're fine with that.
     changePersonData(andrew, 'name', 'Pony');
    
     // Government didn't like the fact that you wanted to change your identity.
     changePersonData(andrew, ID, uniqueId());
  • NonNullable<T> - Exclude null and undefined from T.

    Example Works with strictNullChecks set to true.

    Playground

     type PortNumber = string | number | null;
    
     /** Part of a class definition that is used to build a server */
     class ServerBuilder {
     		portNumber!: NonNullable<PortNumber>;
    
     		port(this: ServerBuilder, port: PortNumber): ServerBuilder {
     				if (port == null) {
     						this.portNumber = 8000;
     				} else {
     						this.portNumber = port;
     				}
    
     				return this;
     		}
     }
    
     const serverBuilder = new ServerBuilder();
    
     serverBuilder
     		.port('8000')   // portNumber = '8000'
     		.port(null)     // portNumber =  8000
     		.port(3000);    // portNumber =  3000
    
     // TypeScript error
     serverBuilder.portNumber = null;
  • Parameters<T> - Obtain the parameters of a function type in a tuple.

    Example

    Playground

     function shuffle(input: any[]): void {
     	// Mutate array randomly changing its' elements indexes.
     }
    
     function callNTimes<Fn extends (...arguments_: any[]) => any> (func: Fn, callCount: number) {
     	// Type that represents the type of the received function parameters.
     	type FunctionParameters = Parameters<Fn>;
    
     	return function (...arguments_: FunctionParameters) {
     		for (let i = 0; i < callCount; i++) {
     			func(...arguments_);
     		}
     	}
     }
    
     const shuffleTwice = callNTimes(shuffle, 2);
  • ConstructorParameters<T> - Obtain the parameters of a constructor function type in a tuple.

    Example

    Playground

     class ArticleModel {
     	title: string;
     	content?: string;
    
     	constructor(title: string) {
     		this.title = title;
     	}
     }
    
     class InstanceCache<T extends (new (...arguments_: any[]) => any)> {
     	private ClassConstructor: T;
     	private cache: Map<string, InstanceType<T>> = new Map();
    
     	constructor (ctr: T) {
     		this.ClassConstructor = ctr;
     	}
    
     	getInstance (...arguments_: ConstructorParameters<T>): InstanceType<T> {
     		const hash = this.calculateArgumentsHash(...arguments_);
    
     		const existingInstance = this.cache.get(hash);
     		if (existingInstance !== undefined) {
     			return existingInstance;
     		}
    
     		return new this.ClassConstructor(...arguments_);
     	}
    
     	private calculateArgumentsHash(...arguments_: any[]): string {
     		// Calculate hash.
     		return 'hash';
     	}
     }
    
     const articleCache = new InstanceCache(ArticleModel);
     const amazonArticle = articleCache.getInstance('Amazon forests burning!');
  • ReturnType<T> - Obtain the return type of a function type.

    Example

    Playground

     /** Provides every element of the iterable `iter` into the `callback` function and stores the results in an array. */
     function mapIter<
     		Elem,
     		Func extends (elem: Elem) => any,
     		Ret extends ReturnType<Func>
     >(iter: Iterable<Elem>, callback: Func): Ret[] {
     		const mapped: Ret[] = [];
    
     		for (const elem of iter) {
     				mapped.push(callback(elem));
     		}
    
     		return mapped;
     }
    
     const setObject: Set<string> = new Set();
     const mapObject: Map<number, string> = new Map();
    
     mapIter(setObject, (value: string) => value.indexOf('Foo')); // number[]
    
     mapIter(mapObject, ([key, value]: [number, string]) => {
     		return key % 2 === 0 ? value : 'Odd';
     }); // string[]
  • InstanceType<T> - Obtain the instance type of a constructor function type.

    Example

    Playground

     class IdleService {
     		doNothing (): void {}
     }
    
     class News {
     		title: string;
     		content: string;
    
     		constructor(title: string, content: string) {
     				this.title = title;
     				this.content = content;
     		}
     }
    
     const instanceCounter: Map<Function, number> = new Map();
    
     interface Constructor {
     		new(...arguments_: any[]): any;
     }
    
     // Keep track how many instances of `Constr` constructor have been created.
     function getInstance<
     		Constr extends Constructor,
     		Arguments extends ConstructorParameters<Constr>
     >(constructor: Constr, ...arguments_: Arguments): InstanceType<Constr> {
     		let count = instanceCounter.get(constructor) || 0;
    
     		const instance = new constructor(...arguments_);
    
     		instanceCounter.set(constructor, count + 1);
    
     		console.log(`Created ${count + 1} instances of ${Constr.name} class`);
    
     		return instance;
     }
    
    
     const idleService = getInstance(IdleService);
     // Will log: `Created 1 instances of IdleService class`
     const newsEntry = getInstance(News, 'New ECMAScript proposals!', 'Last month...');
     // Will log: `Created 1 instances of News class`
  • Omit<T, K> - Constructs a type by picking all properties from T and then removing K.

    Example

    Playground

     interface Animal {
     		imageUrl: string;
     		species: string;
     		images: string[];
     		paragraphs: string[];
     }
    
     // Creates new type with all properties of the `Animal` interface
     // except 'images' and 'paragraphs' properties. We can use this
     // type to render small hover tooltip for a wiki entry list.
     type AnimalShortInfo = Omit<Animal, 'images' | 'paragraphs'>;
    
     function renderAnimalHoverInfo (animals: AnimalShortInfo[]): HTMLElement {
     		const container = document.createElement('div');
     		// Internal implementation.
     		return container;
     }
  • Uppercase<S extends string> - Transforms every character in a string into uppercase.

    Example
     type T = Uppercase<'hello'>;  // 'HELLO'
    
     type T2 = Uppercase<'foo' | 'bar'>;  // 'FOO' | 'BAR'
    
     type T3<S extends string> = Uppercase<`aB${S}`>;
     type T4 = T3<'xYz'>;  // 'ABXYZ'
    
     type T5 = Uppercase<string>;  // string
     type T6 = Uppercase<any>;  // any
     type T7 = Uppercase<never>;  // never
     type T8 = Uppercase<42>;  // Error, type 'number' does not satisfy the constraint 'string'
  • Lowercase<S extends string> - Transforms every character in a string into lowercase.

    Example
     type T = Lowercase<'HELLO'>;  // 'hello'
    
     type T2 = Lowercase<'FOO' | 'BAR'>;  // 'foo' | 'bar'
    
     type T3<S extends string> = Lowercase<`aB${S}`>;
     type T4 = T3<'xYz'>;  // 'abxyz'
    
     type T5 = Lowercase<string>;  // string
     type T6 = Lowercase<any>;  // any
     type T7 = Lowercase<never>;  // never
     type T8 = Lowercase<42>;  // Error, type 'number' does not satisfy the constraint 'string'
  • Capitalize<S extends string> - Transforms the first character in a string into uppercase.

    Example
     type T = Capitalize<'hello'>;  // 'Hello'
    
     type T2 = Capitalize<'foo' | 'bar'>;  // 'Foo' | 'Bar'
    
     type T3<S extends string> = Capitalize<`aB${S}`>;
     type T4 = T3<'xYz'>;  // 'ABxYz'
    
     type T5 = Capitalize<string>;  // string
     type T6 = Capitalize<any>;  // any
     type T7 = Capitalize<never>;  // never
     type T8 = Capitalize<42>;  // Error, type 'number' does not satisfy the constraint 'string'
  • Uncapitalize<S extends string> - Transforms the first character in a string into lowercase.

    Example
     type T = Uncapitalize<'Hello'>;  // 'hello'
    
     type T2 = Uncapitalize<'Foo' | 'Bar'>;  // 'foo' | 'bar'
    
     type T3<S extends string> = Uncapitalize<`AB${S}`>;
     type T4 = T3<'xYz'>;  // 'aBxYz'
    
     type T5 = Uncapitalize<string>;  // string
     type T6 = Uncapitalize<any>;  // any
     type T7 = Uncapitalize<never>;  // never
     type T8 = Uncapitalize<42>;  // Error, type 'number' does not satisfy the constraint 'string'

You can find some examples in the TypeScript docs.

Maintainers

License

SPDX-License-Identifier: (MIT OR CC0-1.0)

More Repositories

1

awesome

😎 Awesome lists about all kinds of interesting topics
270,042
star
2

awesome-nodejs

⚡ Delightful Node.js packages and resources
52,854
star
3

awesome-electron

Useful resources for creating apps with Electron
25,634
star
4

quick-look-plugins

List of useful Quick Look plugins for developers
17,497
star
5

got

🌐 Human-friendly and powerful HTTP request library for Node.js
TypeScript
14,218
star
6

ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
TypeScript
13,762
star
7

pure

Pretty, minimal and fast ZSH prompt
Shell
12,391
star
8

pageres

Capture website screenshots
TypeScript
9,573
star
9

ora

Elegant terminal spinner
JavaScript
8,591
star
10

np

A better `npm publish`
JavaScript
7,529
star
11

github-markdown-css

The minimal amount of CSS to replicate the GitHub Markdown style
CSS
7,421
star
12

caprine

Elegant Facebook Messenger desktop app
TypeScript
7,014
star
13

screenfull

Simple wrapper for cross-browser usage of the JavaScript Fullscreen API
HTML
6,891
star
14

Gifski

🌈 Convert videos to high-quality GIFs on your Mac
Swift
6,807
star
15

fkill-cli

Fabulously kill processes. Cross-platform.
JavaScript
6,782
star
16

query-string

Parse and stringify URL query strings
JavaScript
6,453
star
17

execa

Process execution for humans
JavaScript
6,019
star
18

modern-normalize

🐒 Normalize browsers' default style
TypeScript
5,038
star
19

css-in-readme-like-wat

Style your readme using CSS with this simple trick
5,013
star
20

awesome-npm

Awesome npm resources and tips
4,315
star
21

promise-fun

Promise packages, patterns, chat, and tutorials
4,277
star
22

awesome-scifi

Sci-Fi worth consuming
4,268
star
23

electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
JavaScript
4,165
star
24

create-dmg

Create a good-looking DMG for your macOS app in seconds
JavaScript
3,950
star
25

speed-test

Test your internet connection speed and ping using speedtest.net from the CLI
JavaScript
3,882
star
26

eslint-plugin-unicorn

More than 100 powerful ESLint rules
JavaScript
3,877
star
27

ow

Function argument validation for humans
TypeScript
3,799
star
28

file-type

Detect the file type of a file, stream, or data
JavaScript
3,632
star
29

meow

🐈 CLI app helper
JavaScript
3,305
star
30

p-queue

Promise queue with concurrency control
TypeScript
3,202
star
31

open

Open stuff like URLs, files, executables. Cross-platform.
JavaScript
2,976
star
32

Plash

💦 Make any website your Mac desktop wallpaper
Swift
2,735
star
33

alfy

Create Alfred workflows with ease
JavaScript
2,570
star
34

trash

Move files and directories to the trash
JavaScript
2,512
star
35

fast-cli

Test your download and upload speed using fast.com
JavaScript
2,484
star
36

guides

A collection of succinct guides - Public Domain
2,424
star
37

globby

User-friendly glob matching
JavaScript
2,376
star
38

slugify

Slugify a string
JavaScript
2,357
star
39

emoj

Find relevant emoji from text on the command-line 😮 ✨ 🙌 🐴 💥 🙈
JavaScript
2,311
star
40

cli-spinners

Spinners for use in the terminal
JavaScript
2,255
star
41

on-change

Watch an object or array for changes
JavaScript
1,966
star
42

devtools-detect

Detect if DevTools is open and its orientation
HTML
1,924
star
43

gulp-imagemin

Minify PNG, JPEG, GIF and SVG images
JavaScript
1,903
star
44

touch-bar-simulator

Use the Touch Bar on any Mac
Swift
1,900
star
45

notifier-for-github

Browser extension - Get notified about new GitHub notifications
JavaScript
1,828
star
46

editorconfig-sublime

Sublime Text plugin for EditorConfig - Helps developers maintain consistent coding styles between different editors
Python
1,757
star
47

emittery

Simple and modern async event emitter
JavaScript
1,721
star
48

is

Type check values
TypeScript
1,678
star
49

capture-website

Capture screenshots of websites
JavaScript
1,670
star
50

Defaults

💾 Swifty and modern UserDefaults
Swift
1,661
star
51

electron-boilerplate

Boilerplate to kickstart creating an app with Electron
JavaScript
1,632
star
52

pageres-cli

Capture website screenshots
JavaScript
1,620
star
53

clipboardy

Access the system clipboard (copy/paste)
JavaScript
1,598
star
54

gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
JavaScript
1,538
star
55

pify

Promisify a callback-style function
JavaScript
1,494
star
56

boxen

Create boxes in the terminal
JavaScript
1,467
star
57

Actions

⚙️ Supercharge your shortcuts
Swift
1,437
star
58

multiline

Multiline strings in JavaScript
JavaScript
1,424
star
59

hyper-snazzy

Elegant Hyper theme with bright colors
JavaScript
1,412
star
60

amas

Awesome & Marvelous Amas
1,392
star
61

LaunchAtLogin

Add “Launch at Login” functionality to your macOS app in seconds
Swift
1,346
star
62

del

Delete files and directories
JavaScript
1,316
star
63

refined-twitter

Browser extension that simplifies the Twitter interface and adds useful features
JavaScript
1,313
star
64

KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
Swift
1,313
star
65

iterm2-snazzy

Elegant iTerm2 theme with bright colors
1,313
star
66

electron-context-menu

Context menu for your Electron app
JavaScript
1,297
star
67

p-limit

Run multiple promise-returning & async functions with limited concurrency
JavaScript
1,294
star
68

Settings

⚙ Add a settings window to your macOS app in minutes
Swift
1,282
star
69

trash-cli

Move files and folders to the trash
JavaScript
1,244
star
70

electron-util

Useful utilities for Electron apps and modules
JavaScript
1,188
star
71

is-online

Check if the internet connection is up
JavaScript
1,181
star
72

ponyfill

🦄 Like polyfill but with pony pureness
1,136
star
73

conf

Simple config handling for your app or module
TypeScript
1,109
star
74

anatine

[DEPRECATED] 🐦 Pristine Twitter app
JavaScript
1,097
star
75

electron-dl

Simplified file downloads for your Electron app
JavaScript
1,087
star
76

log-update

Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.
JavaScript
1,027
star
77

pretty-bytes

Convert bytes to a human readable string: 1337 → 1.34 kB
JavaScript
1,022
star
78

grunt-sass

Compile Sass to CSS
JavaScript
1,020
star
79

mem

Memoize functions - an optimization technique used to speed up consecutive function calls by caching the result of calls with identical input
TypeScript
1,019
star
80

DockProgress

Show progress in your app's Dock icon
Swift
1,003
star
81

wallpaper

Manage the desktop wallpaper
JavaScript
996
star
82

p-map

Map over promises concurrently
JavaScript
996
star
83

public-ip

Get your public IP address - very fast!
JavaScript
979
star
84

gulp-app

[DEPRECATED] Gulp as an app
JavaScript
961
star
85

grunt-shell

Run shell commands
JavaScript
952
star
86

load-grunt-tasks

Load multiple grunt tasks using globbing patterns
JavaScript
940
star
87

hasha

Hashing made simple. Get the hash of a buffer/string/stream/file.
JavaScript
934
star
88

pretty-ms

Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
JavaScript
929
star
89

terminal-image

Display images in the terminal
JavaScript
923
star
90

object-assign

ES2015 Object.assign() ponyfill
JavaScript
922
star
91

copy-text-to-clipboard

Copy text to the clipboard in modern browsers (0.2 kB)
JavaScript
858
star
92

System-Color-Picker

🎨 The macOS color picker as an app with more features
Swift
842
star
93

normalize-url

Normalize a URL
JavaScript
818
star
94

get-port

Get an available TCP port
JavaScript
817
star
95

atom-editorconfig

Helps developers maintain consistent coding styles between different editors
JavaScript
811
star
96

grunt-concurrent

Run grunt tasks concurrently
JavaScript
799
star
97

dot-prop

Get, set, or delete a property from a nested object using a dot path
JavaScript
777
star
98

p-progress

Create a promise that reports progress
TypeScript
751
star
99

gulp-changed

Only pass through changed files
JavaScript
747
star
100

generator-nm

Scaffold out a node module
JavaScript
742
star