Skip to content

Types Reference

License NPM Version Open Issues Size

๐Ÿท๏ธ Collection of TypeScript types shared across Lou Codes projects.

Usage

๐Ÿ“ฆ Node

Install @lou.codes/types as a dependency:

Terminal window
1
pnpm add @lou.codes/types
2
# or
3
npm install @lou.codes/types
4
# or
5
yarn add @lou.codes/types

Import as type and use it:

1
import type { Unary } from "@lou.codes/types";

๐Ÿฆ• Deno

Import @lou.codes/types using the npm: prefix, and use it directly:

1
import type { Unary } from "npm:@lou.codes/types";
  • ๐Ÿ“ Documentation: TypeDoc generated documentation.
  • โณ Changelog: List of changes between versions.

Array

ArrayLike<Item, Length>

1
type ArrayLike<Item, Length>: ReadOnlyRecord<NeverFallback<Exclude<Enumerate<Length>, Length>, number>, Item> & object;

An alternative for TypeScriptโ€™s ArrayLike type, with its type set to unknown by default. It also makes it shallowly read-only.

Remarks

When working with optional types, having to type ArrayLike<unknown> every time gets annoying pretty fast. This type is a drop-in replacement for ArrayLike, with the only difference being that the type of the items is set to unknown by default.

Example

1
const arrayLike: ArrayLike<number> = [1, 2, 3];

Type declaration

MemberTypeDescription
lengthLengthAmount of items in the ArrayLike.

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the array-like object.
Length extends numbernumber-

View source


Empty

1
type Empty: EmptyArray | EmptyRecord | EmptyString;

Empty array, object or string.

Remarks

Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.

Example

1
const emptyString: Empty = "";
2
const emptyArray: Empty = [];
3
const emptyRecord: Empty = {};

See

View source


EmptyArray

1
type EmptyArray: typeof EMPTY_ARRAY;

Empty array.

Remarks

This is a type alias for an readonly empty array. Trying to access items on it will give a compile-time error.

Example

1
const emptyArray: EmptyArray = [];

View source


Entry<Key, Value>

1
type Entry<Key, Value>: readonly [Key, Value];

Entry couple [key, value].

Remarks

It is a tuple of two elements, the first one being the key and the second one being the value of an objectโ€™s property.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];

Type parameters

Type parameterValueDescription
KeyPropertyKeyObjectโ€™s properties type.
ValueunknownObjectโ€™s values type.

View source


EntryKey<Input>

1
type EntryKey<Input>: Input[0];

Key of an Entry.

Remarks

Util type to get the key of an Entry.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];
2
const entryKey: EntryKey<typeof entry> = entry[0];

See

Entry

Type parameters

Type parameterDescription
Input extends EntryEntry type.

View source


EntryOf<Type>

1
type EntryOf<Type>: Entry<KeyOf<Type>, ValueOf<Type>>;

Object or array Entry.

Remarks

Get the Entry type out of an object or array.

Example

1
const object = {
2
"๐ŸŸข": 1,
3
"๐ŸŸฉ": 2,
4
};
5
const entries: EntryOf<typeof object> = Object.entries(object)[0];

See

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source


EntryValue<Input>

1
type EntryValue<Input>: Input[1];

Value of an Entry.

Remarks

Util type to get the value of an Entry.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];
2
const entryValue: EntryValue<typeof entry> = entry[1];

See

Entry

Type parameters

Type parameterDescription
Input extends EntryEntry type.

View source


Head<Input>

1
type Head<Input>: HeadAndTail<Input>[0];

Initial value of an ArrayLike.

Remarks

Given a type argument (an ArrayLike), this returns the type of the item in index 0.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const head: Head<typeof array> = "๐ŸŸข";

See

Type parameters

Type parameterDescription
Input extends ArrayLikeArrayLike value (such as Array or string).

View source


HeadAndTail<Input>

1
type HeadAndTail<Input>: Input extends readonly [infer HeadItem, infer TailItems] ? readonly [HeadItem, TailItems] : Input extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [FirstCharacter, RestOfString] : Input extends EmptyArray | EmptyString ? readonly [undefined, Input] : readonly [Maybe<Input[number]>, Input];

Get a couple with the head and tail types of an ArrayLike.

Remarks

Given a type argument (an ArrayLike), this returns a couple with the type of the item in index 0 first, and the rest of the ArrayLike after.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const headAndTail: HeadAndTail<typeof array> = ["๐ŸŸข", ["๐ŸŸฉ", "๐Ÿ’š"]];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeInput ArrayLike.

View source


Initial<Input>

1
type Initial<Input>: InitialAndLast<Input>[0];

Initial values of an ArrayLike (omitting the last).

Remarks

Given a type argument (an ArrayLike), this returns the type of the items from the start of the ArrayLike until the before to last item.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const initial: Initial<typeof array> = ["๐ŸŸข", "๐ŸŸฉ"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeArrayLike value (such as Array or string).

View source


InitialAndLast<Input>

1
type InitialAndLast<Input>: Input extends readonly [...(infer InitialItems), infer LastItem] ? readonly [InitialItems, LastItem] : Input extends EmptyArray | EmptyString ? readonly [Input, undefined] : Input extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [`${RestOfString extends EmptyString ? EmptyString : FirstCharacter}${Head<InitialAndLast<RestOfString>>}`, `${RestOfString extends EmptyString ? FirstCharacter : Last<RestOfString>}`] : readonly [Input, Maybe<Input[number]>];

Get a couple with the initial and last types of an ArrayLike.

Remarks

Given a ArrayLike, this returns a couple with the type of all items from the start until the item before last, and then the last.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const initialAndLast: InitialAndLast<typeof array> = [["๐ŸŸข", "๐ŸŸฉ"], "๐Ÿ’š"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeInput ArrayLike.

View source


KeyOf<Type>

1
type KeyOf<Type>: Type extends ArrayLike ? NeverFallback<Just<Exclude<Partial<Type>["length"], Type["length"]>>, number> : `${Exclude<keyof Type, symbol>}`;

Generic key for either object or array.

Remarks

Type to represent the type of the key in an array or object. It automatically omits symbol keys from objects, and uses number for arrays with dynamic length.

Example

1
const array = [1, 2, 3] as const;
2
const object = { "๐ŸŸข": "๐ŸŸฉ" } as const;
3
4
const arrayKey: KeyOf<typeof array> = 0;
5
const objectKey: KeyOf<typeof object> = "๐ŸŸข";

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source


Last<Input>

1
type Last<Input>: InitialAndLast<Input>[1];

Last value of an ArrayLike.

Remarks

Type of the last character of a string or the last element of an array.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const last: Last<typeof array> = "๐Ÿ’š";

See

Type parameters

Type parameterDescription
Input extends ArrayLikeThe input ArrayLike.

View source


MaybeEmpty<Input>

1
type MaybeEmpty<Input>: Either<Input, Input extends ReadOnlyArray ? EmptyArray : Input extends string ? EmptyString : Input extends ReadOnlyRecord ? EmptyRecord : undefined>;

Creates an union of the given type with a possible โ€œemptyโ€ value.

Remarks

This type is useful to make clear that we expect a possible empty value.

Example

1
type Greet: MaybeEmpty<"Hello">; // "Hello" | ""
2
type Triple: MaybeEmpty<readonly [1, 2, 3]>; // readonly [1, 2, 3] | readonly []
3
type Foo: MaybeEmpty<{ readonly foo: "bar" }>; // { readonly foo: "bar" } | {}

See

Type parameters

Type parameterDescription
InputType to unite with itโ€™s empty counterpart.

View source


NotEmpty<Type>

1
type NotEmpty<Type>: Exclude<Type, Empty>;

Type for a non-empty ArrayLike, object or string.

Remarks

This type is useful for cases where you want to ensure that a value is not empty. For example, if you have an array that should always have at least one element, you could type it as NotEmpty<ArrayLike<ElementType>>.

Example

1
const notEmptyString: NotEmpty<string> = "๐ŸŸข";
2
const notEmptyArray: NotEmpty<ReadOnlyArray> = ["๐ŸŸข", "๐ŸŸฉ"];
3
const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "๐ŸŸข": "๐ŸŸฉ" };

See

Empty

Type parameters

Type parameterDescription
Type extends ArrayLike | object | stringThe type to check.

View source


ReadOnlyArray<Item>

1
type ReadOnlyArray<Item>: ReadonlyArray<Item>;

An alternative for TypeScriptโ€™s ReadonlyArray type, with its type set to unknown by default.

Remarks

Thereโ€™s already a native ReadonlyArray type, but this type has a default type parameter to make it easier to use when the type of an array is unknown.

Example

1
const array: ReadOnlyArray<{ "๐ŸŸข": number }> = [{ "๐ŸŸข": 1 }, { "๐ŸŸข": 2 }];
2
array[0]["๐ŸŸข"] = 3; // Error

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the array.

View source


Reducer<Item, Accumulator>

1
type Reducer<Item, Accumulator>: Unary<Item, Unary<Accumulator, Accumulator>>;

Reducer/Folder function.

Remarks

Type to represent a folder/reducer unary function that takes an item and an accumulator something of the type of the accumulator.

Example

1
const reducer: Reducer<number, number> = item => accumulator =>
2
accumulator + item;

See

Unary

Type parameters

Type parameterDescription
ItemType of the items to reduce.
AccumulatorType of the accumulator/output.

View source


Tail<Input>

1
type Tail<Input>: HeadAndTail<Input>[1];

Last values of an ArrayLike (omitting the first).

Remarks

Type of the last items of an ArrayLike, excluding the first item in said ArrayLike.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const tail: Tail<typeof array> = ["๐ŸŸฉ", "๐Ÿ’š"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeType of the array to get the tail.

View source


ValueOf<Type>

1
type ValueOf<Type>: KeyOf<Type> extends keyof Type ? Type[KeyOf<Type>] : never;

Generic key for either object or array.

Remarks

This type is used to get the type of the values in a collection (items of an ArrayLike or properties of a Record).

Example

1
const object = {
2
"๐ŸŸข": 1,
3
"๐ŸŸฉ": 2,
4
};
5
const key: ValueOf<typeof object> = 1;

See

KeyOf

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source

Common

Awaitable<Type>

1
type Awaitable<Type>: PromiseLike<Type> | Type;

A value that might be coming from a Promise.

Remarks

Union type useful when you want to accept both Promise and non-Promise for a given type, both โ€œawaitableโ€.

Example

1
type AwaitableString = Awaitable<string>;
2
const promisedValue: AwaitableString = Promise.resolve("๐ŸŸข");
3
const plainValue: AwaitableString = "๐ŸŸฉ";
4
5
Promise.all([promisedValue, plainValue]).then(console.log); // ["๐ŸŸข", "๐ŸŸฉ"]

See

Promise

Type parameters

Type parameterValueDescription
TypeunknownThe type to await.

View source


Either<Right, Left>

1
type Either<Right, Left>: Right | Left;

Value that can be something or something else.

Remarks

Union type useful for cases where a value might be of one type or another. By convention we use Right for the โ€œsuccessโ€ type and Left for the error.

Example

1
type MaybeNumber = Either<number, string>;
2
const maybeNumber: MaybeNumber = 1;
3
const notNumber: MaybeNumber = "1";

Type parameters

Type parameterDescription
RightThe โ€œcorrectโ€ type.
LeftThe โ€œerrorโ€ type.

View source


Falsy

1
type Falsy:
2
| EmptyString
3
| HTMLAllCollection
4
| Nullish
5
| 0
6
| 0n
7
| false;

Types that evaluates to false in JS.

Remarks

Union type of the values that evaluate to false in JavaScript. Due to TypeScript type limitations NaN canโ€™t be included.

Example

1
const falsyBoolean: Falsy = false;
2
const falsyHTMLAllCollection: Falsy = document.all;
3
const falsyNegativeZero: Falsy = -0;
4
const falsyNegativeZeroBigInt: Falsy = -0n;
5
const falsyNull: Falsy = null;
6
const falsyString: Falsy = "";
7
const falsyUndefined: Falsy = undefined;
8
const falsyZero: Falsy = 0;
9
const falsyZeroBigInt: Falsy = 0n;

See

View source


JSONValue

1
type JSONValue: Exclude<Primitive, bigint | symbol | undefined> | ReadonlyArray<JSONValue> | object;

Possible parsed JSON value.

Remarks

Following the JSON specification, the result of a JSON.parse call can be one of a given set of types. This type is a union of all of those types.

Example

1
const json: JSONValue = JSON.parse('{"foo": "bar"}');

See

JSON

View source


Just<Input>

1
type Just<Input>: Exclude<Input, undefined>;

Excludes undefined of a type union.

Remarks

Every now and then a type is possibly undefined, this type gets rid of the undefined in the union.

Example

1
const maybeUndefined: string | undefined = "๐ŸŸข";
2
const defined: Just<typeof maybeUndefined> = "๐ŸŸข"; // ok
3
const noDefined: Just<typeof maybeUndefined> = undefined; // error

See

Maybe

Type parameters

Type parameter
Input

View source


Maybe<Input>

1
type Maybe<Input>: Either<Just<Input>, undefined>;

Value that can be undefined.

Remarks

Union type useful for cases where a value might be undefined, and provides a simple way to express this in TypeScript. For example, the return type of a function that returns a string or undefined could be typed as Maybe<string>.

Example

1
type MaybeNumber = Maybe<number>;
2
const maybeNumber: MaybeNumber = 1;
3
const notNumber: MaybeNumber = undefined;

See

Just

Type parameters

Type parameterDescription
InputThe type of the value to make optional.

View source


NeverFallback<MaybeNever, Fallback>

1
type NeverFallback<MaybeNever, Fallback>: Single<MaybeNever> extends Single<never> ? Fallback : MaybeNever;

Takes a value that could be never, and if it is never it goes to the Fallback value.

Remarks

There are some scenarios where a value can end up being of type never, this works sorta like the the ?? operator, but for never.

Example

1
const value: never = undefined as never;
2
NeverFallback<typeof value, number>; // Will be number

See

Single

Type parameters

Type parameterDescription
MaybeNeverThe type that may or may not be never.
FallbackThe fallback type to use if MaybeNever is never.

View source


Nullish

1
type Nullish: Maybe<null>;

Nullish value (either null or undefined).

Remarks

This type is useful for cases where a value might be null or undefined, generally meant to be dealt with using the ?? operator.

Example

1
const nullishUndefined: Nullish = undefined;
2
const nullishNull: Nullish = null;

See

View source


Primitive

1
type Primitive:
2
| Nullish
3
| Numeric
4
| boolean
5
| string
6
| symbol;

Valid JavaScript primitives.

Remarks

This type is a union of all the valid JavaScript primitives, including null, undefined, boolean, number, bigint, string, and symbol.

Example

1
const aBigInt: Primitive = 13n;
2
const aBoolean: Primitive = true;
3
const aNull: Primitive = null;
4
const aNumber: Primitive = 13;
5
const anUndefined: Primitive = undefined;
6
const aString: Primitive = "๐ŸŸข";
7
const aSymbol: Primitive = Symbol("๐ŸŸข");

See

View source


Replace<Type, Keys, NewType>

1
type Replace<Type, Keys, NewType>: Omit<Type, Keys> & { readonly [Property in Keys]: NewType };

Intersection that replaces the type of some keys in given object type.

Remarks

Intersection type to replace all the given keys of an object type with a new type.

Example

1
type User = { name: string; age: number };
2
type ReallyOldUser = Replace<User, "age", bigint>;

Type parameters

Type parameterDescription
Type extends objectType to replace the type of some keys in.
Keys extends keyof TypeKeys to replace the type of.
NewTypeNew type to replace the old type with.

View source


Single<Type>

1
type Single<Type>: readonly [Type];

Tuple of length 1 (AKA Monuple).

Remarks

Tuple with a single element on it, useful when doing optional types that compare to never.

Example

1
const single: Single<boolean> = [true];

Type parameters

Type parameterDescription
TypeType of the single element.

View source


Strigifiable

1
type Strigifiable: Exclude<Primitive, symbol>;

Values that can be stringified.

Remarks

Type to represent all values that can be stringified, all primitives excluding symbol: string, number, bigint, boolean, undefined, and null.

Example

1
let value: Strigifiable = "hello";
2
value = 1;
3
value = true;
4
value = Symbol("hello"); // Error!
5
value = { toString: () => "hello" }; // Error!

See

Primitive

View source


Truthy<Type>

1
type Truthy<Type>: Exclude<Type, Falsy>;

Excludes all Falsy values of the given Type.

Remarks

Type to represent all values of the given Type that are not Falsy. If all types are Falsy, the result is never.

Example

1
Truthy<"" | "truthy">; // "truthy"

See

Falsy

Type parameters

Type parameterValueDescription
TypeunknownType to exclude Falsy values from.

View source


TypeOfDictionary

1
type TypeOfDictionary: object;

typeof dictionary.

Remarks

Dictionary of types and their typeof values, including the proposed but never added type "null" for null.

Example

1
TypeOfMap["string"]; // `string`
2
TypeOfMap["boolean"]; // `boolean`
3
TypeOfMap["function"]; // `GenericFunction`

See

Type declaration

MemberTypeDescription
bigintbigintTypeOfDictionary key for BigInt
booleanbooleanTypeOfDictionary key for Boolean
functionFunctionTypeOfDictionary key for Function
nullnullTypeOfDictionary key for null
numbernumberTypeOfDictionary key for Number
objectobjectTypeOfDictionary key for Object
stringstringTypeOfDictionary key for String
symbolsymbolTypeOfDictionary key for Symbol
undefinedundefinedTypeOfDictionary key for undefined

View source


TypeOfValue

1
type TypeOfValue: KeyOf<TypeOfDictionary>;

Possible type values returned by typeof.

Remarks

Type to represent the possible values returned by typeof, including the proposed but never added type "null" for null.

Example

1
const typeString: TyeOfValue = "string";
2
const typeBoolean: TyeOfValue = "boolean";
3
const typeFunction: TyeOfValue = "function";

See

View source


Unbound<Type>

1
type Unbound<Type>: Type extends ReadonlyArray<infer Item> ? { [Property in keyof ReadonlyArray<Item>]: ReadonlyArray<Item>[Property] extends Function ? Function : ReadonlyArray<Item>[Property] } : { [Property in keyof Type]: Type[Property] extends Function ? Function : Type[Property] };

Type that replaces adds the this: void argument to all the methods in the given Type.

Remarks

This type is used when the unbound of all methods is automated.

Example

1
Unbound < Date > ["getTime"]; // (this: void) => number

Type parameters

Type parameterValueDescription
TypeunknownType to be unbounded.

View source

Date

DayOfMonth

1
type DayOfMonth: Range<1, 31>;

Day of the month values in numeric format (from 1 to 31).

Remarks

Stricter than number type for day of the month values, limited to valid values from 1 to 31, and giving type errors otherwise.

Example

1
const days: Iterable<DayOfMonth> = [1, 2, 3, 28, 29, 30, 31];

See

View source


DayOfWeek

1
type DayOfWeek: Enumerate<6>;

Day of the week values in numeric format (from 0 to 6).

Remarks

Stricter than number type for day of the week values, limited to valid values from 0 to 6, and giving type errors otherwise.

Example

1
const daysOfWeek: Iterable<DayOfWeek> = [0, 1, 2, 3, 4, 5, 6];

See

View source


Hours

1
type Hours: Enumerate<23>;

Hours values in numeric format (from 0 to 23).

Remarks

Stricter than number type for hour values, limited to valid values from 0 to 23, and giving type errors otherwise.

Example

1
const hours: Iterable<Hours> = [0, 1, 2, 3, 20, 21, 22, 23];

See

View source


ISODate

1
type ISODate: `${ISOYear}-${ISOMonth}-${ISODayOfMonth}T${MultiDigitNumberString}:${MultiDigitNumberString}:${MultiDigitNumberString}.${MultiDigitNumberString}Z`;

String representing an ISO date.

Remarks

This type is a string representing an ISO 8601 format of a date (returned by Date#toISOString). It uses MultiDigitNumberString because the type complexity using better types is too hight.

Example

1
const date: ISODate = "2020-01-01T00:00:00.000Z";

See

View source


ISODayOfMonth

1
type ISODayOfMonth: `0${Exclude<Digit, 0>}` | `${1 | 2}${Digit}` | `3${Enumerate<1>}`;

Day of the month values in string format ("01" to "31").

Remarks

Union type stricter than string type for day of the month values, limited to valid values from "01" to "31", and giving type errors otherwise.

Example

1
const days: Iterable<ISODayOfMonth> = ["01", "15", "31"];

See

View source


ISOHours

1
type ISOHours: `${Enumerate<1>}${Digit}` | `2${Enumerate<3>}`;

Hours values in string format (from "00" to "23").

Remarks

Union type stricter than string type for hour values, limited to valid values from "00" to "23", and giving type errors otherwise.

Example

1
const hours: Iterable<ISOHours> = ["00", "06", "23"];

See

View source


ISOMilliseconds

1
type ISOMilliseconds: `${Digit}${Digit}${Digit}`;

ISO milliseconds values in string format (from "000" to "999").

Remarks

Stricter than string type for millisecond values, limited to valid values from "000" to "999", and giving type errors otherwise.

Example

1
const milliseconds: Iterable<ISOMilliseconds> = ["001", "250", "999"];

See

View source


ISOMinutes

1
type ISOMinutes: `${Enumerate<5>}${Digit}`;

ISO minutes values in string format (from "00" to "59").

Remarks

Stricter than string type for minute values, limited to valid values from "00" to "59", and giving type errors otherwise.

Example

1
const minutes: Iterable<ISOMinutes> = ["00", "30", "59"];

See

View source


ISOMonth

1
type ISOMonth: `0${Exclude<Digit, 0>}` | `1${Enumerate<2>}`;

ISO Month values in string format (from "01" to "12").

Remarks

Union type stricter than string type for month values, limited to valid values from "01" to "12", and giving type errors otherwise.

Example

1
const months: Iterable<ISOMonth> = ["01", "06", "12"];

See

View source


ISOSeconds

1
type ISOSeconds: `${Enumerate<5>}${Digit}`;

ISO seconds values in string format (from "00" to "59").

Remarks

Stricter than string type for seconds values, limited to valid values from "00" to "59", and giving type errors otherwise.

Example

1
const seconds: Iterable<ISOSeconds> = ["00", "30", "59"];

See

View source


ISOYear

1
type ISOYear: `${EmptyString | "-00"}${MultiDigitNumberString}`;

ISO year values in string format.

Remarks

Stricter than string type for year values, limited to valid values from "-271821" to "275760", and giving type errors otherwise.

Example

1
const years: Iterable<ISOYear> = ["2020", "-001000", "1989"];

See

Date

View source


Milliseconds

1
type Milliseconds: Enumerate<999>;

ISO milliseconds values in number format (from 0 to 999).

Remarks

Stricter than number type for millisecond values, limited to valid values from 0 to 999, and giving type errors otherwise.

Example

1
const milliseconds: Iterable<Milliseconds> = [1, 250, 999];

See

View source


Minutes

1
type Minutes: Enumerate<59>;

ISO minutes values in number format (from 0 to 59).

Remarks

Stricter than number type for minute values, limited to valid values from 0 to 59, and giving type errors otherwise.

Example

1
const minutes: Iterable<Minutes> = [0, 30, 59];

See

View source


Month

1
type Month: Enumerate<11>;

ISO Month values in number format (from 0 to 11).

Remarks

Stricter than number type for month values, limited to valid values from 0 to 11, and giving type errors otherwise.

Example

1
const months: Iterable<ISOMonth> = [1, 6, 11];

See

View source


Seconds

1
type Seconds: Enumerate<59>;

ISO seconds values in number format (from 0 to 59).

Remarks

Stricter than number type for seconds values, limited to valid values from 0 to 59, and giving type errors otherwise.

Example

1
const seconds: Iterable<Seconds> = [0, 30, 59];

See

View source

Function

Class()<Arguments, Instance>

1
type Class<Arguments, Instance>: (...constructorArguments: Arguments) => Instance;

A generic type for classes.

Remarks

This type is a generic constructor function, mainly used when wrapping classes.

Example

1
const example = (AClass: Class) => new AClass("test");

See

ReadOnlyArray

Type parameters

Type parameterValueDescription
Arguments extends ReadOnlyArrayReadOnlyArrayArguments of the class constructor.
InstanceunknownInstance of the class.

Parameters

ParameterType
โ€ฆconstructorArgumentsArguments

Returns

Instance

View source


Filter<Input>

1
type Filter<Input>: Unary<Input, boolean>;

Unary function that returns a boolean.

Remarks

This type is useful for cases where a function needs to check if a certain condition holds for an input value.

Example

1
const isEven: Filter<number> = number => number % 2 === 0;

See

Param

The input value to check.

Type parameters

Type parameterDescription
InputThe type of the input value.

View source


Predicate()<Input, Predicated>

1
type Predicate<Input, Predicated>: (input: Input) => input is Predicated;

Unary function that returns a boolean and infers a given type for its argument.

Remarks

This type is useful for cases where a function needs to check if a certain condition holds for an input value. For example, the type of a filtering function that filters strings in an array of strings and numbers could look like Predicate<string | number, string>.

Example

1
const isString: Predicate<number | string, string> = (
2
numberOrString,
3
): numberOrString is string => typeof numberOrString === "string";

Type parameters

Type parameterValueDescription
Input-The type of the input value.
Predicated extends InputInputThe subset of Input for which the predicate holds.

Parameters

ParameterTypeDescription
inputInputThe input value to check.

Returns

input is Predicated

View source


ReadOnlyArguments<Input>

1
type ReadOnlyArguments<Input>: Input extends (..._arguments: infer Arguments) => infer _Output ? Readonly<Arguments> : never;

Read-only alternative to TypeScriptโ€™s Parameters

Remarks

This type extracts the parameters of a function as a read-only tuple, similar to Parameters, but with the added benefit of making the parameters read-only.

Example

1
const example = (_foo: string, _bar: number) => undefined;
2
type ExampleArguments = ReadOnlyArguments<typeof example>; // readonly [string, number]

See

Type parameters

Type parameterDescription
Input extends FunctionFunction to extract parameters from.

View source


Reducer<Item, Accumulator>

1
type Reducer<Item, Accumulator>: Unary<Item, Unary<Accumulator, Accumulator>>;

Reducer/Folder function.

Remarks

Type to represent a folder/reducer unary function that takes an item and an accumulator something of the type of the accumulator.

Example

1
const reducer: Reducer<number, number> = item => accumulator =>
2
accumulator + item;

See

Unary

Type parameters

Type parameterDescription
ItemType of the items to reduce.
AccumulatorType of the accumulator/output.

View source


Tagger()<Output, Expressions>

1
type Tagger<Output, Expressions>: (templateStrings: TemplateStringsArray, ...expressions: Expressions) => Output;

Tag function for tagged templates.

Remarks

Type to represent a tag function for tagged templates, which takes a TemplateStringArray and any number of expressions, and returns a value of type Output (string by default).

Example

1
const intParser: Tagger<number> = strings => parseInt(strings.join(""), 10);
2
intParser`100`; // 100

See

ReadOnlyArray

Type parameters

Type parameterValueDescription
OutputstringType of the output value.
Expressions extends ReadOnlyArrayReadOnlyArrayType of the expressions.

Parameters

ParameterType
templateStringsTemplateStringsArray
โ€ฆexpressionsExpressions

Returns

Output

View source


Unary()<Input, Output>

1
type Unary<Input, Output>: (input: Input) => Output;

Unary function.

Remarks

Type to represent a function that takes a single argument, ideal for currying.

Example

1
const unary: Unary<number, number> = number => number + 1;

See

Type parameters

Type parameterDescription
InputType of the input value.
OutputType of the output value.

Parameters

ParameterType
inputInput

Returns

Output

View source


UnaryInput<UnaryFunction>

1
type UnaryInput<UnaryFunction>: UnaryFunction extends Unary<infer Input, infer _Output> ? Input : never;

Unary function input type.

Remarks

This type is used to get the input type of a Unary function.

Example

1
const unary: Unary<number, string> = number => `${number}`;
2
UnaryInput<typeof unary>; // `number`

See

Unary

Type parameters

Type parameterDescription
UnaryFunction extends Unary<never, unknown>Type of the unary function to get the input type of.

View source


UnaryOutput<UnaryFunction>

1
type UnaryOutput<UnaryFunction>: UnaryFunction extends Unary<infer _Input, infer Output> ? Output : never;

Unary function output type.

Remarks

This type is used to get the output type of a Unary function.

Example

1
const unary: Unary<number, string> = number => `${number}`;
2
UnaryOutput<typeof unary>; // `string`

See

Unary

Type parameters

Type parameterDescription
UnaryFunction extends Unary<never, unknown>Type of the unary function to get the output type of.

View source

HTML

HTMLElementTagAttributeMap

1
type HTMLElementTagAttributeMap: ReadOnlyRecord<`${string}-${string}`, HTMLElementTagGlobalAttributes> & object;

Map of HTML element tag attributes.

Remarks

If you need the type of the HTML attributes of an HTML element, this is it.

Example

1
const getAttribute =
2
<Tag extends keyof HTMLElementTagAttributeMap>(tag: Tag) =>
3
(attribute: keyof HTMLElementTagAttributeMap[Tag]) => // โ€ฆ

See

Type declaration

MemberTypeDescription
aHTMLElementTagGlobalAttributes & objectIf the a element has an href attribute, then it represents a hyperlink (a hypertext anchor) labeled by its contents.

---

References

See
MDN Reference
abbrHTMLElementTagGlobalAttributesThe abbr element represents an abbreviation or acronym, optionally with its expansion. The title attribute may be used to provide an expansion of the abbreviation. The attribute, if specified, must contain an expansion of the abbreviation, and nothing else.

---

References

See
MDN Reference
addressHTMLElementTagGlobalAttributesThe address element represents the contact information for its nearest article or body element ancestor. If that is the body element, then the contact information applies to the document as a whole.

---

References

See
MDN Reference
areaHTMLElementTagGlobalAttributes & objectThe area element represents either a hyperlink with some text and a corresponding area on an image map, or a dead area on an image map.

---

References

See
MDN Reference
articleHTMLElementTagGlobalAttributesThe article element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. Each article should be identified, typically by including a heading (h1โ€“h6 element) as a child of the article element.

---

References

See
MDN Reference
asideHTMLElementTagGlobalAttributesThe aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.

---

References

See
MDN Reference
audioHTMLElementTagGlobalAttributes & objectAn audio element represents a sound or audio stream.

---

References

See
MDN Reference
bHTMLElementTagGlobalAttributesThe b element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede.

---

References

See
MDN Reference
baseHTMLElementTagGlobalAttributes & objectThe base element allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information.

---

References

See
MDN Reference
bdiHTMLElementTagGlobalAttributesThe bdi element represents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting. [BIDI]

---

References

See
MDN Reference
bdoHTMLElementTagGlobalAttributes & objectThe bdo element represents explicit text directionality formatting control for its children. It allows authors to override the Unicode bidirectional algorithm by explicitly specifying a direction override. [BIDI]

---

References

See
MDN Reference
blockquoteHTMLElementTagGlobalAttributes & objectThe blockquote element represents content that is quoted from another source, optionally with a citation which must be within a footer or cite element, and optionally with in-line changes such as annotations and abbreviations.

---

References

See
MDN Reference
bodyHTMLElementTagGlobalAttributes & objectThe body element represents the content of the document.

---

References

See
MDN Reference
brHTMLElementTagGlobalAttributes & objectThe br element represents a line break.

---

References

See
MDN Reference
buttonHTMLElementTagGlobalAttributes & objectThe button element represents a button labeled by its contents.

---

References

See
MDN Reference
canvasHTMLElementTagGlobalAttributes & objectThe canvas element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, art, or other visual images on the fly.

---

References

See
MDN Reference
captionHTMLElementTagGlobalAttributes & objectThe caption element represents the title of the table that is its parent, if it has a parent and that is a table element.

---

References

See
MDN Reference
citeHTMLElementTagGlobalAttributesThe cite element represents a reference to a creative work. It must include the title of the work or the name of the author(person, people or organization) or an URL reference, or a reference in abbreviated form as per the conventions used for the addition of citation metadata.

---

References

See
MDN Reference
codeHTMLElementTagGlobalAttributesThe code element represents a fragment of computer code. This could be an XML element name, a file name, a computer program, or any other string that a computer would recognize.

---

References

See
MDN Reference
colHTMLElementTagGlobalAttributes & objectIf a col element has a parent and that is a colgroup element that itself has a parent that is a table element, then the col element represents one or more columns in the column group represented by that colgroup.

---

References

See
MDN Reference
colgroupHTMLElementTagGlobalAttributes & objectThe colgroup element represents a group of one or more columns in the table that is its parent, if it has a parent and that is a table element.

---

References

See
MDN Reference
dataHTMLElementTagGlobalAttributes & objectThe data element links a given piece of content with a machine-readable translation.

---

References

See
MDN Reference
datalistHTMLElementTagGlobalAttributesThe datalist element represents a set of option elements that represent predefined options for other controls. In the rendering, the datalist element represents nothing and it, along with its children, should be hidden.

---

References

See
MDN Reference
ddHTMLElementTagGlobalAttributes & objectThe dd element represents the description, definition, or value, part of a term-description group in a description list (dl element).

---

References

See
MDN Reference
delHTMLElementTagGlobalAttributes & objectThe del element represents a removal from the document.

---

References

See
MDN Reference
detailsHTMLElementTagGlobalAttributes & objectThe details element represents a disclosure widget from which the user can obtain additional information or controls.

---

References

See
MDN Reference
dfnHTMLElementTagGlobalAttributesThe dfn element represents the defining instance of a term. The paragraph, description list group, or section that is the nearest ancestor of the dfn element must also contain the definition(s) for the term given by the dfn element.

---

References

See
MDN Reference
dialogHTMLElementTagGlobalAttributes & objectThe dialog element represents a part of an application that a user interacts with to perform a task, for example a dialog box, inspector, or window.

---

References

See
MDN Reference
divHTMLElementTagGlobalAttributesThe div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.

---

References

See
MDN Reference
dlHTMLElementTagGlobalAttributesThe dl element represents an association list consisting of zero or more name-value groups (a description list). A name-value group consists of one or more names (dt elements) followed by one or more values (dd elements), ignoring any nodes other than dt and dd elements. Within a single dl element, there should not be more than one dt element for each name.

---

References

See
MDN Reference
dtHTMLElementTagGlobalAttributesThe dt element represents the term, or name, part of a term-description group in a description list (dl element).

---

References

See
MDN Reference
emHTMLElementTagGlobalAttributesThe em element represents stress emphasis of its contents.

---

References

See
MDN Reference
embedHTMLElementTagGlobalAttributes & objectThe embed element provides an integration point for an external (typically non-HTML) application or interactive content.

---

References

See
MDN Reference
fieldsetHTMLElementTagGlobalAttributes & objectThe fieldset element represents a set of form controls optionally grouped under a common name.

---

References

See
MDN Reference
figcaptionHTMLElementTagGlobalAttributesThe figcaption element represents a caption or legend for the rest of the contents of the figcaption elementโ€™s parent figure element, if any.

---

References

See
MDN Reference
figureHTMLElementTagGlobalAttributesThe figure element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document.

---

References

See
MDN Reference
footerHTMLElementTagGlobalAttributesThe footer element represents a footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.

---

References

See
MDN Reference
formHTMLElementTagGlobalAttributes & objectThe form element represents a collection of form-associated elements, some of which can represent editable values that can be submitted to a server for processing.

---

References

See
MDN Reference
h1HTMLElementTagGlobalAttributesThe h1 element represents a section heading.

---

References

See
MDN Reference
h2HTMLElementTagGlobalAttributesThe h2 element represents a section heading.

---

References

See
MDN Reference
h3HTMLElementTagGlobalAttributesThe h3 element represents a section heading.

---

References

See
MDN Reference
h4HTMLElementTagGlobalAttributesThe h4 element represents a section heading.

---

References

See
MDN Reference
h5HTMLElementTagGlobalAttributesThe h5 element represents a section heading.

---

References

See
MDN Reference
h6HTMLElementTagGlobalAttributesThe h6 element represents a section heading.

---

References

See
MDN Reference
headHTMLElementTagGlobalAttributes & objectThe head element represents a collection of metadata for the Document.

---

References

See
MDN Reference
headerHTMLElementTagGlobalAttributesThe header element represents introductory content for its nearest ancestor sectioning content or sectioning root element. A header typically contains a group of introductory or navigational aids. When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.

---

References

See
MDN Reference
hgroupHTMLElementTagGlobalAttributesThe hgroup element represents a heading and related content. It groups a single h1โ€“h6 element with one or more p.

---

References

See
MDN Reference
hrHTMLElementTagGlobalAttributes & objectThe hr element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book.

---

References

See
MDN Reference
htmlHTMLElementTagGlobalAttributes & objectThe html element represents the root of an HTML document.

---

References

See
MDN Reference
iHTMLElementTagGlobalAttributesThe i element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.

---

References

See
MDN Reference
iframeHTMLElementTagGlobalAttributes & objectThe iframe element represents a nested browsing context.

---

References

See
MDN Reference
imgHTMLElementTagGlobalAttributes & objectAn img element represents an image.

---

References

See
MDN Reference
inputHTMLElementTagGlobalAttributes & objectThe input element represents a typed data field, usually with a form control to allow the user to edit the data.

---

References

See
MDN Reference
insHTMLElementTagGlobalAttributes & objectThe ins element represents an addition to the document.

---

References

See
MDN Reference
kbdHTMLElementTagGlobalAttributesThe kbd element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).

---

References

See
MDN Reference
labelHTMLElementTagGlobalAttributes & objectThe label element represents a caption in a user interface. The caption can be associated with a specific form control, known as the label elementโ€™s labeled control, either using the for attribute, or by putting the form control inside the label element itself.

---

References

See
MDN Reference
legendHTMLElementTagGlobalAttributesThe legend element represents a caption for the rest of the contents of the legend elementโ€™s parent fieldset element, if any.

---

References

See
MDN Reference
liHTMLElementTagGlobalAttributes & objectThe li element represents a list item. If its parent element is an ol, ul, or menu element, then the element is an item of the parent elementโ€™s list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other li element.

---

References

See
MDN Reference
linkHTMLElementTagGlobalAttributes & objectThe link element allows authors to link their document to other resources.

---

References

See
MDN Reference
mainHTMLElementTagGlobalAttributesThe main element represents the main content of the body of a document or application. The main content area consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.

---

References

See
MDN Reference
mapHTMLElementTagGlobalAttributes & objectThe map element, in conjunction with an img element and any area element descendants, defines an image map. The element represents its children.

---

References

See
MDN Reference
markHTMLElementTagGlobalAttributesThe mark element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. When used in a quotation or other block of text referred to from the prose, it indicates a highlight that was not originally present but which has been added to bring the readerโ€™s attention to a part of the text that might not have been considered important by the original author when the block was originally written, but which is now under previously unexpected scrutiny. When used in the main prose of a document, it indicates a part of the document that has been highlighted due to its likely relevance to the userโ€™s current activity.

---

References

See
MDN Reference
menuHTMLElementTagGlobalAttributesThe menu element represents an unordered list of interactive items.

---

References

See
MDN Reference
metaHTMLElementTagGlobalAttributes & objectThe meta element represents various kinds of metadata that cannot be expressed using the title, base, link, style, and script elements.

---

References

See
MDN Reference
meterHTMLElementTagGlobalAttributes & objectThe meter element represents a scalar measurement within a known range, or a fractional value; for example disk usage, the relevance of a query result, or the fraction of a voting population to have selected a particular candidate.

---

References

See
MDN Reference
navHTMLElementTagGlobalAttributesThe nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.

---

References

See
MDN Reference
noscriptHTMLElementTagGlobalAttributesThe noscript element represents nothing if scripting is enabled, and represents its children if scripting is disabled. It is used to present different markup to user agents that support scripting and those that donโ€™t support scripting, by affecting how the document is parsed.

---

References

See
MDN Reference
objectHTMLElementTagGlobalAttributes & objectThe object element can represent an external resource, which, depending on the type of the resource, will either be treated as an image, as a nested browsing context, or as an external resource to be processed by a plugin.

---

References

See
MDN Reference
olHTMLElementTagGlobalAttributes & objectThe ol element represents a list of items, where the items have been intentionally ordered, such that changing the order would change the meaning of the document.

---

References

See
MDN Reference
optgroupHTMLElementTagGlobalAttributes & objectThe optgroup element represents a group of option elements with a common label.

---

References

See
MDN Reference
optionHTMLElementTagGlobalAttributes & objectThe option element represents an option in a select element or as part of a list of suggestions in a datalist element.

---

References

See
MDN Reference
outputHTMLElementTagGlobalAttributes & objectThe output element represents the result of a calculation performed by the application, or the result of a user action.

---

References

See
MDN Reference
pHTMLElementTagGlobalAttributesThe p element represents a paragraph.

---

References

See
MDN Reference
paramHTMLElementTagGlobalAttributes & objectThe param element defines parameters for plugins invoked by object elements. It does not represent anything on its own.

---

References

See
MDN Reference
pictureHTMLElementTagGlobalAttributesThe picture element is a container which provides multiple sources to its contained img element to allow authors to declaratively control or give hints to the user agent about which image resource to use, based on the screen pixel density, viewport size, image format, and other factors. It represents its children.

---

References

See
MDN Reference
preHTMLElementTagGlobalAttributes & objectThe pre element represents a block of preformatted text, in which structure is represented by typographic conventions rather than by elements.

---

References

See
MDN Reference
progressHTMLElementTagGlobalAttributes & objectThe progress element represents the completion progress of a task. The progress is either indeterminate, indicating that progress is being made but that it is not clear how much more work remains to be done before the task is complete (e.g. because the task is waiting for a remote host to respond), or the progress is a number in the range zero to a maximum, giving the fraction of work that has so far been completed.

---

References

See
MDN Reference
qHTMLElementTagGlobalAttributes & objectThe q element represents some phrasing content quoted from another source.

---

References

See
MDN Reference
rbHTMLElementTagGlobalAttributesThe rb element marks the base text component of a ruby annotation. When it is the child of a ruby element, it doesnโ€™t represent anything itself, but its parent ruby element uses it as part of determining what it represents.

---

References

See
MDN Reference
rpHTMLElementTagGlobalAttributesThe rp element is used to provide fallback text to be shown by user agents that donโ€™t support ruby annotations. One widespread convention is to provide parentheses around the ruby text component of a ruby annotation.

---

References

See
MDN Reference
rtHTMLElementTagGlobalAttributesThe rt element marks the ruby text component of a ruby annotation. When it is the child of a ruby element or of an rtc element that is itself the child of a ruby element, it doesnโ€™t represent anything itself, but its ancestor ruby element uses it as part of determining what it represents.

---

References

See
MDN Reference
rubyHTMLElementTagGlobalAttributesThe ruby element allows one or more spans of phrasing content to be marked with ruby annotations. Ruby annotations are short runs of text presented alongside base text, primarily used in East Asian typography as a guide for pronunciation or to include other annotations. In Japanese, this form of typography is also known as furigana. Ruby text can appear on either side, and sometimes both sides, of the base text, and it is possible to control its position using CSS. A more complete introduction to ruby can be found in the Use Cases & Exploratory Approaches for Ruby Markup document as well as in CSS Ruby Module Level 1. [RUBY-UC] [CSSRUBY]

---

References

See
MDN Reference
sHTMLElementTagGlobalAttributesThe s element represents contents that are no longer accurate or no longer relevant.

---

References

See
MDN Reference
sampHTMLElementTagGlobalAttributesThe samp element represents sample or quoted output from another program or computing system.

---

References

See
MDN Reference
scriptHTMLElementTagGlobalAttributes & objectThe script element allows authors to include dynamic script and data blocks in their documents. The element does not represent content for the user.

---

References

See
MDN Reference
sectionHTMLElementTagGlobalAttributesThe section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content. Each section should be identified, typically by including a heading ( h1- h6 element) as a child of the section element.

---

References

See
MDN Reference
selectHTMLElementTagGlobalAttributes & objectThe select element represents a control for selecting amongst a set of options.

---

References

See
MDN Reference
slotHTMLElementTagGlobalAttributes & objectThe slot element is a placeholder inside a web component that you can fill with your own markup, which lets you create separate DOM trees and present them together.

---

References

See
MDN Reference
smallHTMLElementTagGlobalAttributesThe small element represents side comments such as small print.

---

References

See
MDN Reference
sourceHTMLElementTagGlobalAttributes & objectThe source element allows authors to specify multiple alternative media resources for media elements. It does not represent anything on its own.

---

References

See
MDN Reference
spanHTMLElementTagGlobalAttributesThe span element doesnโ€™t mean anything on its own, but can be useful when used together with the global attributes, e.g. class, lang, or dir. It represents its children.

---

References

See
MDN Reference
strongHTMLElementTagGlobalAttributesThe strong element represents strong importance, seriousness, or urgency for its contents.

---

References

See
MDN Reference
styleHTMLElementTagGlobalAttributes & objectThe style element allows authors to embed style information in their documents. The style element is one of several inputs to the styling processing model. The element does not represent content for the user.

---

References

See
MDN Reference
subHTMLElementTagGlobalAttributesThe sub element represents a subscript.

---

References

See
MDN Reference
summaryHTMLElementTagGlobalAttributesThe summary element represents a summary, caption, or legend for the rest of the contents of the summary elementโ€™s parent details element, if any.

---

References

See
MDN Reference
supHTMLElementTagGlobalAttributesThe sup element represents a superscript.

---

References

See
MDN Reference
tableHTMLElementTagGlobalAttributes & objectThe table element represents data with more than one dimension, in the form of a table.

---

References

See
MDN Reference
tbodyHTMLElementTagGlobalAttributes & objectThe tbody element represents a block of rows that consist of a body of data for the parent table element, if the tbody element has a parent and it is a table.

---

References

See
MDN Reference
tdHTMLElementTagGlobalAttributes & objectThe td element represents a data cell in a table.

---

References

See
MDN Reference
templateHTMLElementTagGlobalAttributesThe template element is used to declare fragments of HTML that can be cloned and inserted in the document by script.

---

References

See
MDN Reference
textareaHTMLElementTagGlobalAttributes & objectThe textarea element represents a multiline plain text edit control for the elementโ€™s raw value. The contents of the control represent the controlโ€™s default value.

---

References

See
MDN Reference
tfootHTMLElementTagGlobalAttributes & objectThe tfoot element represents the block of rows that consist of the column summaries (footers) for the parent table element, if the tfoot element has a parent and it is a table.

---

References

See
MDN Reference
thHTMLElementTagGlobalAttributes & objectThe th element represents a header cell in a table.

---

References

See
MDN Reference
theadHTMLElementTagGlobalAttributes & objectThe thead element represents the block of rows that consist of the column labels (headers) for the parent table element, if the thead element has a parent and it is a table.

---

References

See
MDN Reference
timeHTMLElementTagGlobalAttributes & objectThe time element represents its contents, along with a machine-readable form of those contents in the datetime attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and durations, as described below.

---

References

See
MDN Reference
titleHTMLElementTagGlobalAttributesThe title element represents the documentโ€™s title or name. Authors should use titles that identify their documents even when they are used out of context, for example in a userโ€™s history or bookmarks, or in search results. The documentโ€™s title is often different from its first heading, since the first heading does not have to stand alone when taken out of context.

---

References

See
MDN Reference
trHTMLElementTagGlobalAttributes & objectThe tr element represents a row of cells in a table.

---

References

See
MDN Reference
trackHTMLElementTagGlobalAttributes & objectThe track element allows authors to specify explicit external timed text tracks for media elements. It does not represent anything on its own.

---

References

See
MDN Reference
uHTMLElementTagGlobalAttributesThe u element represents a span of text with an unarticulated, though explicitly rendered, non-textual annotation, such as labeling the text as being a proper name in Chinese text (a Chinese proper name mark), or labeling the text as being misspelt.

---

References

See
MDN Reference
ulHTMLElementTagGlobalAttributes & objectThe ul element represents a list of items, where the order of the items is not important โ€” that is, where changing the order would not materially change the meaning of the document.

---

References

See
MDN Reference
varHTMLElementTagGlobalAttributesThe var element represents a variable. This could be an actual variable in a mathematical expression or programming context, an identifier representing a constant, a symbol identifying a physical quantity, a function parameter, or just be a term used as a placeholder in prose.

---

References

See
MDN Reference
videoHTMLElementTagGlobalAttributes & objectA video element is used for playing videos or movies, and audio files with captions.

---

References

See
MDN Reference
wbrHTMLElementTagGlobalAttributesThe wbr element represents a line break opportunity.

---

References

See
MDN Reference

View source


HTMLElementTagGlobalAttributes

1
type HTMLElementTagGlobalAttributes: object;

Global HTML attributes.

Remarks

If you need the type of all HTML attributes, this is it.

Example

1
const getAttribute = (attribute: keyof HTMLElementTagGlobalAttributes) => // โ€ฆ

See

ReadOnlyRecord

Type declaration

MemberTypeDescription
accesskeystringProvides a hint for generating a keyboard shortcut for the current element. This attribute consists of a space-separated list of characters. The browser should use the first one that exists on the computer keyboard layout.

---

References

See
MDN Reference
aria-activedescendantstringIdentifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.

---

References

See
WAI-ARIA Reference
aria-atomicstringIndicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.

---

References

See
WAI-ARIA Reference
aria-autocompletestringIndicates whether inputting text could trigger display of one or more predictions of the userโ€™s intended value for an input and specifies how predictions would be presented if they are made.

---

References

See
WAI-ARIA Reference
aria-busystringIndicates an element is being modified and that assistive technologies MAY want to wait until the modifications are complete before exposing them to the user.

---

References

See
WAI-ARIA Reference
aria-checkedstringIndicates the current โ€œcheckedโ€ state of checkboxes, radio buttons, and other widgets. See related aria-pressed and aria-selected.

---

References

See
WAI-ARIA Reference
aria-colcountstringDefines the total number of columns in a table, grid, or treegrid. See related aria-colindex.

---

References

See
WAI-ARIA Reference
aria-colindexstringDefines an elementโ€™s column index or position with respect to the total number of columns within a table, grid, or treegrid. See related aria-colcount and aria-colspan.

---

References

See
WAI-ARIA Reference
aria-colspanstringDefines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-colindex and aria-rowspan.

---

References

See
WAI-ARIA Reference
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.

---

References

See
WAI-ARIA Reference
aria-currentstringIndicates the element that represents the current item within a container or set of related elements.

---

References

See
WAI-ARIA Reference
aria-describedbystringIdentifies the element (or elements) that describes the object. See related aria-labelledby.

---

References

See
WAI-ARIA Reference
aria-detailsstringIdentifies the element that provides a detailed, extended description for the object. See related aria-describedby.
aria-disabledstringIndicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.

---

References

See
WAI-ARIA Reference
aria-dropeffectstring[Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.

---

References

See
WAI-ARIA Reference
aria-errormessagestringIdentifies the element that provides an error message for the object. See related aria-invalid and aria-describedby.

---

References

See
WAI-ARIA Reference
aria-expandedstringIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.

---

References

See
WAI-ARIA Reference
aria-flowtostringIdentifies the next element (or elements) in an alternate reading order of content which, at the userโ€™s discretion, allows assistive technology to override the general default of reading in document source order.

---

References

See
WAI-ARIA Reference
aria-grabbedstring[Deprecated in ARIA 1.1] Indicates an elementโ€™s โ€œgrabbedโ€ state in a drag-and-drop operation.

---

References

See
WAI-ARIA Reference
aria-haspopupstringIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.

---

References

See
WAI-ARIA Reference
aria-hiddenstringIndicates whether the element is exposed to an accessibility API. See related aria-disabled.

---

References

See
WAI-ARIA Reference
aria-invalidstringIndicates the entered value does not conform to the format expected by the application. See related aria-errormessage.

---

References

See
WAI-ARIA Reference
aria-keyshortcutsstringIndicates keyboard shortcuts that an author has implemented to activate or give focus to an element.
aria-labelstringDefines a string value that labels the current element. See related aria-labelledby.

---

References

See
WAI-ARIA Reference
aria-labelledbystringIdentifies the element (or elements) that labels the current element. See related aria-describedby.

---

References

See
WAI-ARIA Reference
aria-levelstringDefines the hierarchical level of an element within a structure.

---

References

See
WAI-ARIA Reference
aria-livestringIndicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.

---

References

See
WAI-ARIA Reference
aria-modalstringIndicates whether an element is modal when displayed.

---

References

See
WAI-ARIA Reference
aria-multilinestringIndicates whether a text box accepts multiple lines of input or only a single line.

---

References

See
WAI-ARIA Reference
aria-multiselectablestringIndicates that the user may select more than one item from the current selectable descendants.

---

References

See
WAI-ARIA Reference
aria-orientationstringIndicates whether the elementโ€™s orientation is horizontal, vertical, or unknown/ambiguous.

---

References

See
WAI-ARIA Reference
aria-ownsstringIdentifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. See related aria-controls.

---

References

See
WAI-ARIA Reference
aria-placeholderstringDefines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.

---

References

See
WAI-ARIA Reference
aria-posinsetstringDefines an elementโ€™s number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-setsize.

---

References

See
WAI-ARIA Reference
aria-pressedstringIndicates the current โ€œpressedโ€ state of toggle buttons. See related aria-checked and aria-selected.

---

References

See
WAI-ARIA Reference
aria-readonlystringIndicates that the element is not editable, but is otherwise operable. See related aria-disabled.

---

References

See
WAI-ARIA Reference
aria-relevantstringIndicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.

---

References

See
WAI-ARIA Reference
aria-requiredstringIndicates that user input is required on the element before a form may be submitted.

---

References

See
WAI-ARIA Reference
aria-roledescriptionstringDefines a human-readable, author-localized description for the role of an element.

---

References

See
WAI-ARIA Reference
aria-rowcountstringDefines the total number of rows in a table, grid, or treegrid. See related aria-rowindex.

---

References

See
WAI-ARIA Reference
aria-rowindexstringDefines an elementโ€™s row index or position with respect to the total number of rows within a table, grid, or treegrid. See related aria-rowcount and aria-rowspan.

---

References

See
WAI-ARIA Reference
aria-rowspanstringDefines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-rowindex and aria-colspan.

---

References

See
WAI-ARIA Reference
aria-selectedstringIndicates the current โ€œselectedโ€ state of various widgets. See related aria-checked and aria-pressed.

---

References

See
WAI-ARIA Reference
aria-setsizestringDefines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-posinset.

---

References

See
WAI-ARIA Reference
aria-sortstringIndicates if items in a table or grid are sorted in ascending or descending order.

---

References

See
WAI-ARIA Reference
aria-valuemaxstringDefines the maximum allowed value for a range widget.

---

References

See
WAI-ARIA Reference
aria-valueminstringDefines the minimum allowed value for a range widget.

---

References

See
WAI-ARIA Reference
aria-valuenowstringDefines the current value for a range widget. See related aria-valuetext.

---

References

See
WAI-ARIA Reference
aria-valuetextstringDefines the human readable text alternative of aria-valuenow for a range widget.

---

References

See
WAI-ARIA Reference
autocapitalizestringControls whether and how text input is automatically capitalized as it is entered/edited by the user. It can have the following values:

_ off or none, no autocapitalization is applied (all letters default to lowercase)
_ on or sentences, the first letter of each sentence defaults to a capital letter; all other letters default to lowercase
_ words, the first letter of each word defaults to a capital letter; all other letters default to lowercase
_ characters, all letters should default to uppercase

---

References

See
MDN Reference
classstringA space-separated list of the classes of the element. Classes allows CSS and JavaScript to select and access specific elements via the class selectors or functions like the method Document.getElementsByClassName().

---

References

See
MDN Reference
contenteditablestringAn enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing. The attribute must take one of the following values:

_ true or the empty string, which indicates that the element must be editable;
_ false, which indicates that the element must not be editable.

---

References

See
MDN Reference
contextmenustringThe [**id**](#attr-id) of a <menu> to use as the contextual menu for this element.

---

References

See
MDN Reference
dirstringAn enumerated attribute indicating the directionality of the elementโ€™s text. It can have the following values:

_ ltr, which means left to right and is to be used for languages that are written from the left to the right (like English);
_ rtl, which means right to left and is to be used for languages that are written from the right to the left (like Arabic);
* auto, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then it applies that directionality to the whole element.

---

References

See
MDN Reference
draggablestringAn enumerated attribute indicating whether the element can be dragged, using the Drag and Drop API. It can have the following values:

_ true, which indicates that the element may be dragged
_ false, which indicates that the element may not be dragged.

---

References

See
MDN Reference
dropzonestringAn enumerated attribute indicating what types of content can be dropped on an element, using the Drag and Drop API. It can have the following values:

_ copy, which indicates that dropping will create a copy of the element that was dragged
_ move, which indicates that the element that was dragged will be moved to this new location.
* link, will create a link to the dragged data.
exportpartsstringUsed to transitively export shadow parts from a nested shadow tree into a containing light tree.

---

References

See
MDN Reference
hiddenstringA Boolean attribute indicates that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that canโ€™t be used until the login process has been completed. The browser wonโ€™t render such elements. This attribute must not be used to hide content that could legitimately be shown.

---

References

See
MDN Reference
idstringDefines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).

---

References

See
MDN Reference
inputmodestringProvides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents. Used primarily on <input> elements, but is usable on any element while in [contenteditable](https://developer.mozilla.org/docs/Web/HTML/Global_attributes#attr-contenteditable) mode.

---

References

See
MDN Reference
isstringAllows you to specify that a standard HTML element should behave like a registered custom built-in element (see Using custom elements for more details).

---

References

See
MDN Reference
itemidstringThe unique, global identifier of an item.

---

References

See
MDN Reference
itempropstringUsed to add properties to an item. Every HTML element may have an itemprop attribute specified, where an itemprop consists of a name and value pair.

---

References

See
MDN Reference
itemrefstringProperties that are not descendants of an element with the itemscope attribute can be associated with the item using an itemref. It provides a list of element ids (not itemids) with additional properties elsewhere in the document.

---

References

See
MDN Reference
itemscopestringitemscope (usually) works along with [itemtype](https://developer.mozilla.org/docs/Web/HTML/Global_attributes#attr-itemtype) to specify that the HTML contained in a block is about a particular item. itemscope creates the Item and defines the scope of the itemtype associated with it. itemtype is a valid URL of a vocabulary (such as schema.org) that describes the item and its properties context.

---

References

See
MDN Reference
itemtypestringSpecifies the URL of the vocabulary that will be used to define itemprops (item properties) in the data structure. [itemscope](https://developer.mozilla.org/docs/Web/HTML/Global_attributes#attr-itemscope) is used to set the scope of where in the data structure the vocabulary set by itemtype will be active.

---

References

See
MDN Reference
langstringHelps define the language of an element: the language that non-editable elements are in, or the language that editable elements should be written in by the user. The attribute contains one โ€œlanguage tagโ€ (made of hyphen-separated โ€œlanguage subtagsโ€) in the format defined in Tags for Identifying Languages (BCP47). xml:lang has priority over it.

---

References

See
MDN Reference
onabortstringThe loading of a resource has been aborted.
onblurstringAn element has lost focus (does not bubble).
oncanplaystringThe user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
oncanplaythroughstringThe user agent can play the media up to its end without having to stop for further buffering of content.
onchangestringThe change event is fired for ,
onclickstringA pointing device button has been pressed and released on an element.
oncontextmenustringThe right button of the mouse is clicked (before the context menu is displayed).
ondblclickstringA pointing device button is clicked twice on an element.
ondragstringAn element or text selection is being dragged (every 350ms).
ondragendstringA drag operation is being ended (by releasing a mouse button or hitting the escape key).
ondragenterstringA dragged element or text selection enters a valid drop target.
ondragleavestringA dragged element or text selection leaves a valid drop target.
ondragoverstringAn element or text selection is being dragged over a valid drop target (every 350ms).
ondragstartstringThe user starts dragging an element or text selection.
ondropstringAn element is dropped on a valid drop target.
ondurationchangestringThe duration attribute has been updated.
onemptiedstringThe media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it.
onendedstringPlayback has stopped because the end of the media was reached.
onerrorstringA resource failed to load.
onfocusstringAn element has received focus (does not bubble).
onformchangestring-
onforminputstring-
oninputstringThe value of an element changes or the content of an element with the attribute contenteditable is modified.
oninvalidstringA submittable element has been checked and doesnโ€™t satisfy its constraints.
onkeydownstringA key is pressed down.
onkeypressstringA key is pressed down and that key normally produces a character value (use input instead).
onkeyupstringA key is released.
onloadstringA resource and its dependent resources have finished loading.
onloadeddatastringThe first frame of the media has finished loading.
onloadedmetadatastringThe metadata has been loaded.
onloadstartstringProgress has begun.
onmousedownstringA pointing device button (usually a mouse) is pressed on an element.
onmouseenterstringA pointing device is moved onto the element that has the listener attached.
onmouseleavestringA pointing device is moved off the element that has the listener attached.
onmousemovestringA pointing device is moved over an element.
onmouseoutstringA pointing device is moved off the element that has the listener attached or off one of its children.
onmouseoverstringA pointing device is moved onto the element that has the listener attached or onto one of its children.
onmouseupstringA pointing device button is released over an element.
onmousewheelstring-
onpausestringPlayback has been paused.
onplaystringPlayback has begun.
onplayingstringPlayback is ready to start after having been paused or delayed due to lack of data.
onpointercancelstringThe pointer is unlikely to produce any more events.
onpointerdownstringThe pointer enters the active buttons state.
onpointerenterstringPointing device is moved inside the hit-testing boundary.
onpointerleavestringPointing device is moved out of the hit-testing boundary.
onpointerlockchangestringThe pointer was locked or released.
onpointerlockerrorstringIt was impossible to lock the pointer for technical reasons or because the permission was denied.
onpointermovestringThe pointer changed coordinates.
onpointeroutstringThe pointing device moved out of hit-testing boundary or leaves detectable hover range.
onpointeroverstringThe pointing device is moved into the hit-testing boundary.
onpointerupstringThe pointer leaves the active buttons state.
onprogressstringIn progress.
onratechangestringThe playback rate has changed.
onreadystatechangestringThe readyState attribute of a document has changed.
onresetstringA form is reset.
onresizestringThe document view has been resized.
onscrollstringThe document view or an element has been scrolled.
onseekedstringA seek operation completed.
onseekingstringA seek operation began.
onselectstringSome text is being selected.
onshowstringA contextmenu event was fired on/bubbled to an element that has a contextmenu attribute
onstalledstringThe user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
onsubmitstringA form is submitted.
onsuspendstringMedia data loading has been suspended.
ontimeupdatestringThe time indicated by the currentTime attribute has been updated.
onvolumechangestringThe volume has changed.
onwaitingstringPlayback has stopped because of a temporary lack of data.
partstringA space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element.

---

References

See
MDN Reference
rolestring-
slotstringAssigns a slot in a shadow DOM shadow tree to an element: An element with a slot attribute is assigned to the slot created by the <slot> element whose [name](https://developer.mozilla.org/docs/Web/HTML/Element/slot#attr-name) attributeโ€™s value matches that slot attributeโ€™s value.

---

References

See
MDN Reference
spellcheckstringAn enumerated attribute defines whether the element may be checked for spelling errors. It may have the following values:

_ true, which indicates that the element should be, if possible, checked for spelling errors;
_ false, which indicates that the element should not be checked for spelling errors.

---

References

See
MDN Reference
stylestringContains CSS styling declarations to be applied to the element. Note that it is recommended for styles to be defined in a separate file or files. This attribute and the <style> element have mainly the purpose of allowing for quick styling, for example for testing purposes.

---

References

See
MDN Reference
tabindexstringAn integer attribute indicating if the element can take input focus (is focusable), if it should participate to sequential keyboard navigation, and if so, at what position. It can take several values:

_ a negative value means that the element should be focusable, but should not be reachable via sequential keyboard navigation;
_ 0 means that the element should be focusable and reachable via sequential keyboard navigation, but its relative order is defined by the platform convention;
* a positive value means that the element should be focusable and reachable via sequential keyboard navigation; the order in which the elements are focused is the increasing value of the tabindex. If several elements share the same tabindex, their relative order follows their relative positions in the document.

---

References

See
MDN Reference
titlestringContains a text representing advisory information related to the element it belongs to. Such information can typically, but not necessarily, be presented to the user as a tooltip.

---

References

See
MDN Reference
translatestringAn enumerated attribute that is used to specify whether an elementโ€™s attribute values and the values of its Text node children are to be translated when the page is localized, or whether to leave them unchanged. It can have the following values:

_ empty string and yes, which indicates that the element will be translated.
_ no, which indicates that the element will not be translated.

---

References

See
MDN Reference

View source

Iterables

IsomorphicIterable<Item>

1
type IsomorphicIterable<Item>: Readonly<AsyncIterable<Item> | Iterable<Item>>;

Value might be an AsyncIterable or just an Iterable (read-only).

Remarks

Union type useful when you want to accept both AsyncIterable and Iterable values, which is generally in asynchronous functions that can loop over @@asyncIterator or @@iterator values.

Example

1
const iterable: IsomorphicIterable<number> = [1, 2, 3];
2
3
for (const item of iterable) {
4
console.log(item); // Works
5
}
6
7
for await (const item of iterable) {
8
console.log(item); // Also works
9
}

See

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the iterable.

View source


IsomorphicIterableItem<SourceIterable>

1
type IsomorphicIterableItem<SourceIterable>: SourceIterable extends IsomorphicIterable<infer Item> ? Item : never;

Type of the items of an IsomorphicIterable.

Remarks

Sometimes we have to get the item type out of an IsomorphicIterable. This type is meant to be used where inference is not an option.

Example

1
const iterable: IsomorphicIterable<number> = [1, 2, 3];
2
const item: IsomorphicIterableItem<typeof iterable> = 1;

See

IsomorphicIterable

Type parameters

Type parameterDescription
SourceIterable extends IsomorphicIterableIsomorphicIterable type to get the item type from.`

View source


IsomorphicIterableIterator<Item>

1
type IsomorphicIterableIterator<Item>: Readonly<AsyncIterableIterator<Item> | IterableIterator<Item>>;

Value might be an AsyncIterableIterator or just an IterableIterator (read-only).

Remarks

This is just an read-only alternative to AsyncIterableIterator or IterableIterator to avoid unwanted mutations.

Example

1
const iterable: IsomorphicIterableIterator<number> = [1, 2, 3];

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the AsyncIterableIterator or
IterableIterator.

View source


IsomorphicIterator<Item, Return, Next>

1
type IsomorphicIterator<Item, Return, Next>: Readonly<AsyncIterator<Item, Return, Next> | Iterator<Item, Return, Next>>;

Value might be an AsyncIterator or just an Iterator (read-only).

Remarks

This is just an read-only alternative to AsyncIterator or Iterator to avoid unwanted mutations.

Example

1
const iterator: IsomorphicIterator<number> = [1, 2, 3];

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the AsyncIterator or Iterator.
ReturnvoidType of the return value in the AsyncIterator or Iterator.
NextvoidType of the next value in the AsyncIterator or Iterator.

View source


ReadOnlyIterable<Item>

1
type ReadOnlyIterable<Item>: Readonly<Iterable<Item>>;

Read-only Iterable.

Remarks

This is just an read-only alternative to Iterable to avoid unwanted mutations.

Example

1
const test1: ReadOnlyIterable<number> = [1, 2, 3]; // ok
2
const test2: ReadOnlyIterable<string> = [1, 2, 3]; // error

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the Iterable.

View source


ReadOnlyIterableIterator<Item>

1
type ReadOnlyIterableIterator<Item>: Readonly<IterableIterator<Item>>;

Read-only IterableIterator.

Remarks

This is just an read-only alternative to IterableIterator to avoid unwanted mutations.

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the IterableIterator.

View source


ReadOnlyIterator<Item, Return, Next>

1
type ReadOnlyIterator<Item, Return, Next>: Readonly<Iterator<Item, Return, Next>>;

Read-only Iterator.

Remarks

This is just an read-only alternative to Iterator to avoid unwanted mutations.

Type parameters

Type parameterValueDescription
ItemunknownType of the items in the Iterator.
ReturnvoidType of the return value in the Iterator.
NextvoidType of the next value in the Iterator.

View source

Number

Digit

1
type Digit: Enumerate<9>;

Valid digits (0 to 9).

Remarks

The idea with this type is to use it to construct others based on it, like for example Digit2 for 00 to 99.

Example

1
const numbers: Iterable<Digit> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

See

Enumerate

View source


Enumerate<To, Accumulator>

1
type Enumerate<To, Accumulator>: Accumulator["length"] extends To ? Accumulator[number] | To : Enumerate<To, [...Accumulator, Accumulator["length"]]>;

Union of numbers from 0 to To

Remarks

Recursively generates a type with an union of numbers from 0 to Length - 1. This has the same limit TypeScript has for recursive types.

Example

1
type From0To10 = Enumerate<10>;

Type parameters

Type parameterValueDescription
To extends number-Last number of the union (starts at 0).
Accumulator extends ReadonlyArray<number>[]Accumulator for the recursion (for internal use).

View source


MultiDigitNumberString

1
type MultiDigitNumberString: `${bigint}${bigint}`;

String with more than 1 number on it.

Remarks

This type is useful when a given string will need more than one number on it.

Example

1
const test1: MultiDigitNumberString = "01"; // ok
2
const test2: MultiDigitNumberString = "1"; // error

View source


Numeric

1
type Numeric: bigint | number;

Types to represent numbers.

Remarks

The Numeric type is a union of number and bigint. It is useful for cases where a value could be either a regular JavaScript number or a BigInt.

Example

1
const numericNumber: Numeric = 42;
2
const numericBigInt: Numeric = 42n;

View source


Radix

1
type Radix: Range<2, 36>;

Valid radix values (from 2 to 36).

Remarks

The Radix type is useful when working with number bases other than decimal. The radix defines the base of the number system being used. For example, a binary system has a radix of 2, a decimal system has a radix of 10, and a hexadecimal system has a radix of 16. The Radix type can be used to ensure that a given radix value is within the valid range of 2 to 36.

Example

1
const binary: Radix = 2;
2
const decimal: Radix = 10;
3
const hexadecimal: Radix = 16;

See

Range

View source


Range<From, To>

1
type Range<From, To>: Exclude<Enumerate<To>, Enumerate<From>> | From;

Generates a range of numbers using Enumerate with given Length and omitting the first From numbers.

Remarks

This type is equivalent to an array of numbers where the first From elements are excluded and the length of the array is Length - From. The idea is to use it to generate a range of numbers from the given From, and of the given Length.

Example

1
type From5To10 = Range<5, 10>; // 5, 6, 7, 8, 9, 10

See

Enumerate

Type parameters

Type parameter
From extends number
To extends number

View source

Object

Empty

1
type Empty: EmptyArray | EmptyRecord | EmptyString;

Empty array, object or string.

Remarks

Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.

Example

1
const emptyString: Empty = "";
2
const emptyArray: Empty = [];
3
const emptyRecord: Empty = {};

See

View source


EmptyRecord

1
type EmptyRecord: ReadOnlyRecord<PropertyKey, never>;

Empty record (object).

Remarks

This is a type alias for an empty readonly record. Accessing properties gives undefined.

Example

1
const emptyRecord: EmptyRecord = {};

See

ReadOnlyRecord

View source


Entry<Key, Value>

1
type Entry<Key, Value>: readonly [Key, Value];

Entry couple [key, value].

Remarks

It is a tuple of two elements, the first one being the key and the second one being the value of an objectโ€™s property.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];

Type parameters

Type parameterValueDescription
KeyPropertyKeyObjectโ€™s properties type.
ValueunknownObjectโ€™s values type.

View source


EntryKey<Input>

1
type EntryKey<Input>: Input[0];

Key of an Entry.

Remarks

Util type to get the key of an Entry.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];
2
const entryKey: EntryKey<typeof entry> = entry[0];

See

Entry

Type parameters

Type parameterDescription
Input extends EntryEntry type.

View source


EntryOf<Type>

1
type EntryOf<Type>: Entry<KeyOf<Type>, ValueOf<Type>>;

Object or array Entry.

Remarks

Get the Entry type out of an object or array.

Example

1
const object = {
2
"๐ŸŸข": 1,
3
"๐ŸŸฉ": 2,
4
};
5
const entries: EntryOf<typeof object> = Object.entries(object)[0];

See

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source


EntryValue<Input>

1
type EntryValue<Input>: Input[1];

Value of an Entry.

Remarks

Util type to get the value of an Entry.

Example

1
const entry: Entry<string, number> = ["๐ŸŸข", 1];
2
const entryValue: EntryValue<typeof entry> = entry[1];

See

Entry

Type parameters

Type parameterDescription
Input extends EntryEntry type.

View source


KeyOf<Type>

1
type KeyOf<Type>: Type extends ArrayLike ? NeverFallback<Just<Exclude<Partial<Type>["length"], Type["length"]>>, number> : `${Exclude<keyof Type, symbol>}`;

Generic key for either object or array.

Remarks

Type to represent the type of the key in an array or object. It automatically omits symbol keys from objects, and uses number for arrays with dynamic length.

Example

1
const array = [1, 2, 3] as const;
2
const object = { "๐ŸŸข": "๐ŸŸฉ" } as const;
3
4
const arrayKey: KeyOf<typeof array> = 0;
5
const objectKey: KeyOf<typeof object> = "๐ŸŸข";

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source


MaybeEmpty<Input>

1
type MaybeEmpty<Input>: Either<Input, Input extends ReadOnlyArray ? EmptyArray : Input extends string ? EmptyString : Input extends ReadOnlyRecord ? EmptyRecord : undefined>;

Creates an union of the given type with a possible โ€œemptyโ€ value.

Remarks

This type is useful to make clear that we expect a possible empty value.

Example

1
type Greet: MaybeEmpty<"Hello">; // "Hello" | ""
2
type Triple: MaybeEmpty<readonly [1, 2, 3]>; // readonly [1, 2, 3] | readonly []
3
type Foo: MaybeEmpty<{ readonly foo: "bar" }>; // { readonly foo: "bar" } | {}

See

Type parameters

Type parameterDescription
InputType to unite with itโ€™s empty counterpart.

View source


NotEmpty<Type>

1
type NotEmpty<Type>: Exclude<Type, Empty>;

Type for a non-empty ArrayLike, object or string.

Remarks

This type is useful for cases where you want to ensure that a value is not empty. For example, if you have an array that should always have at least one element, you could type it as NotEmpty<ArrayLike<ElementType>>.

Example

1
const notEmptyString: NotEmpty<string> = "๐ŸŸข";
2
const notEmptyArray: NotEmpty<ReadOnlyArray> = ["๐ŸŸข", "๐ŸŸฉ"];
3
const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "๐ŸŸข": "๐ŸŸฉ" };

See

Empty

Type parameters

Type parameterDescription
Type extends ArrayLike | object | stringThe type to check.

View source


ReadOnlyRecord<Key, Value>

1
type ReadOnlyRecord<Key, Value>: Readonly<Record<Key, Value>>;

Read-only record.

Remarks

Thereโ€™s already a native Readonly and Record type, but this type has default type parameters to make it easier to use when the type of a record is unknown.

Example

1
const record: ReadOnlyRecord<string, Array<number>> = {
2
"๐ŸŸข": [1, 2, 3],
3
"๐ŸŸฉ": [4, 5, 6],
4
};
5
record["๐ŸŸข"][0] = 7; // Error

Type parameters

Type parameterValueDescription
Key extends PropertyKeyPropertyKeyType of the keys in the record.
ValueunknownType of the values in the record.

View source


ValueOf<Type>

1
type ValueOf<Type>: KeyOf<Type> extends keyof Type ? Type[KeyOf<Type>] : never;

Generic key for either object or array.

Remarks

This type is used to get the type of the values in a collection (items of an ArrayLike or properties of a Record).

Example

1
const object = {
2
"๐ŸŸข": 1,
3
"๐ŸŸฉ": 2,
4
};
5
const key: ValueOf<typeof object> = 1;

See

KeyOf

Type parameters

Type parameterDescription
Type extends objectObject or array type.

View source

RegExp

RegularExpression

1
type RegularExpression: `/${string}/${RegularExpressionFlags}`;

String representing a regular expression.

Remarks

Safer than string and simpler than RegExp type to represent a regular expression. It RegularExpression to enforce flags to always have u and have a consistent order.

Example

1
const regex: RegularExpression = "/^[a-z]+$/u";

See

View source


RegularExpressionFlags

1
type RegularExpressionFlags: `${MaybeEmpty<"g">}${MaybeEmpty<"i">}${MaybeEmpty<"m">}${MaybeEmpty<"s">}u`;

Possible combinations of regular expression flags (with mandatory u flag).

Remarks

Type union stricter than string type for RegExp flags. The unicode flag is mandatory to ensure unicode characters are always supported.

Example

1
const flags1: RegularExpressionFlags = "u";
2
const flags2: RegularExpressionFlags = "gu";
3
const flags3: RegularExpressionFlags = "iu";
4
const flags4: RegularExpressionFlags = "giu";

See

Regular Expressions

View source

String

Empty

1
type Empty: EmptyArray | EmptyRecord | EmptyString;

Empty array, object or string.

Remarks

Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.

Example

1
const emptyString: Empty = "";
2
const emptyArray: Empty = [];
3
const emptyRecord: Empty = {};

See

View source


EmptyString

1
type EmptyString: typeof EMPTY_STRING;

Empty string.

Remarks

This type is a string with no characters on it (length 0). EmptyString.

Example

1
const emptyString: EmptyString = "";

View source


Head<Input>

1
type Head<Input>: HeadAndTail<Input>[0];

Initial value of an ArrayLike.

Remarks

Given a type argument (an ArrayLike), this returns the type of the item in index 0.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const head: Head<typeof array> = "๐ŸŸข";

See

Type parameters

Type parameterDescription
Input extends ArrayLikeArrayLike value (such as Array or string).

View source


HeadAndTail<Input>

1
type HeadAndTail<Input>: Input extends readonly [infer HeadItem, infer TailItems] ? readonly [HeadItem, TailItems] : Input extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [FirstCharacter, RestOfString] : Input extends EmptyArray | EmptyString ? readonly [undefined, Input] : readonly [Maybe<Input[number]>, Input];

Get a couple with the head and tail types of an ArrayLike.

Remarks

Given a type argument (an ArrayLike), this returns a couple with the type of the item in index 0 first, and the rest of the ArrayLike after.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const headAndTail: HeadAndTail<typeof array> = ["๐ŸŸข", ["๐ŸŸฉ", "๐Ÿ’š"]];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeInput ArrayLike.

View source


Initial<Input>

1
type Initial<Input>: InitialAndLast<Input>[0];

Initial values of an ArrayLike (omitting the last).

Remarks

Given a type argument (an ArrayLike), this returns the type of the items from the start of the ArrayLike until the before to last item.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const initial: Initial<typeof array> = ["๐ŸŸข", "๐ŸŸฉ"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeArrayLike value (such as Array or string).

View source


InitialAndLast<Input>

1
type InitialAndLast<Input>: Input extends readonly [...(infer InitialItems), infer LastItem] ? readonly [InitialItems, LastItem] : Input extends EmptyArray | EmptyString ? readonly [Input, undefined] : Input extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [`${RestOfString extends EmptyString ? EmptyString : FirstCharacter}${Head<InitialAndLast<RestOfString>>}`, `${RestOfString extends EmptyString ? FirstCharacter : Last<RestOfString>}`] : readonly [Input, Maybe<Input[number]>];

Get a couple with the initial and last types of an ArrayLike.

Remarks

Given a ArrayLike, this returns a couple with the type of all items from the start until the item before last, and then the last.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const initialAndLast: InitialAndLast<typeof array> = [["๐ŸŸข", "๐ŸŸฉ"], "๐Ÿ’š"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeInput ArrayLike.

View source


Last<Input>

1
type Last<Input>: InitialAndLast<Input>[1];

Last value of an ArrayLike.

Remarks

Type of the last character of a string or the last element of an array.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const last: Last<typeof array> = "๐Ÿ’š";

See

Type parameters

Type parameterDescription
Input extends ArrayLikeThe input ArrayLike.

View source


LocaleIdentifier

1
type LocaleIdentifier:
2
| "eo"
3
| "yue-Hant-HK"
4
| LocaleString<"af", `${"N" | "Z"}A`>
5
| LocaleString<"ak", "GH">
6
| LocaleString<"am", "ET">
7
| LocaleString<"ar",
8
| `${"A" | "Y"}E`
9
| "BH"
10
| "DZ"
11
| `E${"G" | "H" | "R"}`
12
| `I${"L" | "Q"}`
13
| "JO"
14
| "KW"
15
| `I${"B" | "Y"}`
16
| `M${"A" | "R"}`
17
| "OM"
18
| "PS"
19
| "QA"
20
| `S${"A" | "D" | "O" | "S" | "Y"}`
21
| `T${"D" | "N"}`>
22
| LocaleString<"as", "IN">
23
| LocaleString<"asa", "TZ">
24
| LocaleString<"az", LocaleString<"Cyrl" | "Latn", "AZ">>
25
| LocaleString<"be", "BY">
26
| LocaleString<"bem", "ZM">
27
| LocaleString<"bez", "TZ">
28
| LocaleString<"bg", "BG">
29
| LocaleString<"bm", "ML">
30
| LocaleString<"bn", "BD" | "IN">
31
| LocaleString<"bo", `${"C" | "I"}N`>
32
| LocaleString<"bs", "BA">
33
| LocaleString<"ca", "ES">
34
| LocaleString<"cgg", "UG">
35
| LocaleString<"chr", "US">
36
| LocaleString<"cs", "CZ">
37
| LocaleString<"cy", "GB">
38
| LocaleString<"da", "DK">
39
| LocaleString<"dav", "KE">
40
| LocaleString<"de", "AT" | `${"B" | "D"}E` | "CH" | `L${"I" | "U"}`>
41
| LocaleString<"ebu", "KE">
42
| LocaleString<"ee", "GH" | "TG">
43
| LocaleString<"el", "CY" | "GR">
44
| LocaleString<"en",
45
| `A${"S" | "U"}`
46
| `B${"E" | "W" | "Z"}`
47
| "CA"
48
| `G${"B" | "U"}`
49
| "HK"
50
| "IE"
51
| `I${"L" | "N"}`
52
| "JM"
53
| `M${"H" | "P" | "T" | "U"}`
54
| `N${"A" | "Z"}`
55
| `P${"H" | "K"}`
56
| "SG"
57
| "TT"
58
| `U${"M" | "S"}`
59
| "VI"
60
| `Z${"A" | "W"}`>
61
| LocaleString<"es",
62
| "419"
63
| "AR"
64
| "BO"
65
| `C${"L" | "O" | "R"}`
66
| "DO"
67
| `E${"C" | "S"}`
68
| `G${"Q" | "T"}`
69
| "HN"
70
| "MX"
71
| "NI"
72
| `P${"A" | "E" | "R" | "Y"}`
73
| "SV"
74
| `U${"S" | "Y"}`
75
| "VE">
76
| LocaleString<"et", "EE">
77
| LocaleString<"eu", "ES">
78
| LocaleString<"fa", "AF" | "IR">
79
| LocaleString<"ff", "SN">
80
| LocaleString<"fi", "FI">
81
| LocaleString<"fil", "PH">
82
| LocaleString<"fo", "FO">
83
| LocaleString<"fr",
84
| `B${"E" | "F" | "I" | "J" | "L"}`
85
| `C${"A" | "D" | "F" | "G" | "H" | "I" | "M"}`
86
| "DJ"
87
| "FR"
88
| `G${"A" | "N" | "P" | "Q"}`
89
| "KM"
90
| "LU"
91
| `M${"C" | "F" | "G" | "L" | "Q"}`
92
| "NE"
93
| `R${"E" | "W"}`
94
| "SN"
95
| `T${"D" | "G"}`>
96
| LocaleString<"ga", "IE">
97
| LocaleString<"gl", "ES">
98
| LocaleString<"gsw", "CH">
99
| LocaleString<"gu", "IN">
100
| LocaleString<"guz", "KE">
101
| LocaleString<"gv", "GB">
102
| LocaleString<"ha", LocaleString<"Latn", "GH" | `N${"E" | "G"}`>>
103
| LocaleString<"haw", "US">
104
| LocaleString<"he", "IL">
105
| LocaleString<"hi", "IN">
106
| LocaleString<"hr", "HR">
107
| LocaleString<"hu", "HU">
108
| LocaleString<"hy", "AM">
109
| LocaleString<"id", "ID">
110
| LocaleString<"ig", "NG">
111
| LocaleString<"ii", "CN">
112
| LocaleString<"is", "IS">
113
| LocaleString<"it", "CH" | "IT">
114
| LocaleString<"ja", "JP">
115
| LocaleString<"jmc", "TZ">
116
| LocaleString<"ka", "GE">
117
| LocaleString<"kab", "DZ">
118
| LocaleString<"kam", "KE">
119
| LocaleString<"kde", "TZ">
120
| LocaleString<"kea", "CV">
121
| LocaleString<"khq", "ML">
122
| LocaleString<"ki", "KE">
123
| LocaleString<"kk", LocaleString<"Cyrl", "KZ">>
124
| LocaleString<"kl", "GL">
125
| LocaleString<"kln", "KE">
126
| LocaleString<"km", "KH">
127
| LocaleString<"kn", "IN">
128
| LocaleString<"ko", "KR">
129
| LocaleString<"kok", "IN">
130
| LocaleString<"kw", "GB">
131
| LocaleString<"lag", "TZ">
132
| LocaleString<"lg", "UG">
133
| LocaleString<"lt", "LT">
134
| LocaleString<"luo", "KE">
135
| LocaleString<"luy", "KE">
136
| LocaleString<"lv", "LV">
137
| LocaleString<"mas", "KE" | "TZ">
138
| LocaleString<"mer", "KE">
139
| LocaleString<"mfe", "MU">
140
| LocaleString<"mg", "MG">
141
| LocaleString<"mk", "MK">
142
| LocaleString<"ml", "IN">
143
| LocaleString<"mr", "IN">
144
| LocaleString<"ms", "BN" | "MY">
145
| LocaleString<"mt", "MT">
146
| LocaleString<"my", "MM">
147
| LocaleString<"naq", "NA">
148
| LocaleString<"nb", "NO">
149
| LocaleString<"nd", "ZW">
150
| LocaleString<"ne", "IN" | "NP">
151
| LocaleString<"nl", "BE" | "NL">
152
| LocaleString<"nn", "NO">
153
| LocaleString<"nyn", "UG">
154
| LocaleString<"om", "ET" | "KE">
155
| LocaleString<"or", "IN">
156
| LocaleString<"pa", LocaleString<"Arab", "PK"> | LocaleString<"Guru", "IN">>
157
| LocaleString<"pl", "PL">
158
| LocaleString<"ps", "AF">
159
| LocaleString<"pt", "BR" | "GW" | "MZ" | "PT">
160
| LocaleString<"rm", "CH">
161
| LocaleString<"ro", "MD" | "RO">
162
| LocaleString<"rof", "TZ">
163
| LocaleString<"ru", "MD" | "RU" | "UA">
164
| LocaleString<"rw", "RW">
165
| LocaleString<"rwk", "TZ">
166
| LocaleString<"saq", "KE">
167
| LocaleString<"seh", "MZ">
168
| LocaleString<"ses", "ML">
169
| LocaleString<"sg", "CF">
170
| LocaleString<"shi", LocaleString<"Latn" | "Tfng", "MA">>
171
| LocaleString<"si", "LK">
172
| LocaleString<"sk", "SK">
173
| LocaleString<"sl", "SI">
174
| LocaleString<"sn", "ZW">
175
| LocaleString<"so", "DJ" | "ET" | "KE" | "SO">
176
| LocaleString<"sq", "AL">
177
| LocaleString<"sr", LocaleString<"Cyrl" | "Latn", "BA" | "ME" | "RS">>
178
| LocaleString<"sv", "FI" | "SE">
179
| LocaleString<"sw", "KE" | "TZ">
180
| LocaleString<"ta", "IN" | "LK">
181
| LocaleString<"te", "IN">
182
| LocaleString<"teo", "KE" | "UG">
183
| LocaleString<"th", "TH">
184
| LocaleString<"ti", `E${"R" | "T"}`>
185
| LocaleString<"to", "TO">
186
| LocaleString<"tr", "TR">
187
| LocaleString<"tzm", LocaleString<"Latn", "MA">>
188
| LocaleString<"uk", "UA">
189
| LocaleString<"ur", "IN" | "PK">
190
| LocaleString<"uz", LocaleString<"Arab", "AF"> | LocaleString<"Cyrl" | "Latn", "UZ">>
191
| LocaleString<"vi", "VN">
192
| LocaleString<"vun", "TZ">
193
| LocaleString<"xog", "UG">
194
| LocaleString<"yo", "NG">
195
| LocaleString<"zh", LocaleString<`Han${"s" | "t"}`, "HK" | "MO"> | LocaleString<"Hans", "CN" | "SG"> | LocaleString<"Hant", "TW">>
196
| LocaleString<"zu", "ZA">;

Locale identifiers (language-country).

Remarks

When using i18n tools, this is a stricter union type than string to handle the locale identifiers.

Example

1
const locale: LocaleIdentifier = "en-US";

See

EmptyString

View source


LocaleString<LanguageCode, CountryCodes, Separator>

1
type LocaleString<LanguageCode, CountryCodes, Separator>: `${LanguageCode}${MaybeEmpty<`${Separator}${CountryCodes}`>}`;

String for locales such as โ€œen-USโ€.

Remarks

This type mainly exists to make LocaleIdentifier a little bit easier to the eyes.

Example

1
type English1: LocaleIdentifier<"en", "US" | "UK">; // "en" | "en-US" | "en-UK"
2
type English2: LocaleIdentifier<"en", "US" | "UK", "_">; // "en" | "en_US" | "en_UK"

See

LocaleIdentifier

Type parameters

Type parameterValueDescription
LanguageCode extends MultiCharacterString-2 character language code.
CountryCodes extends MultiCharacterString-Union of country codes.
Separator extends "-" | "_""-"-

View source


MaybeEmpty<Input>

1
type MaybeEmpty<Input>: Either<Input, Input extends ReadOnlyArray ? EmptyArray : Input extends string ? EmptyString : Input extends ReadOnlyRecord ? EmptyRecord : undefined>;

Creates an union of the given type with a possible โ€œemptyโ€ value.

Remarks

This type is useful to make clear that we expect a possible empty value.

Example

1
type Greet: MaybeEmpty<"Hello">; // "Hello" | ""
2
type Triple: MaybeEmpty<readonly [1, 2, 3]>; // readonly [1, 2, 3] | readonly []
3
type Foo: MaybeEmpty<{ readonly foo: "bar" }>; // { readonly foo: "bar" } | {}

See

Type parameters

Type parameterDescription
InputType to unite with itโ€™s empty counterpart.

View source


MultiCharacterString

1
type MultiCharacterString: `${string}${string}`;

String with more than 1 character on it.

Deprecated

Not actually deprecated, this type doesnโ€™t do anything yet.

Remarks

This type will be useful when a given string will need more than one character on it. Sadly this type doesnโ€™t work because TypeScript considers "" a string, so "" + "" === string, same for "f" + "" which is not a multi character string.

Example

1
const test1: MultiCharacterString = "foo"; // ok
2
const test2: MultiCharacterString = "f"; // error

View source


MultiDigitNumberString

1
type MultiDigitNumberString: `${bigint}${bigint}`;

String with more than 1 number on it.

Remarks

This type is useful when a given string will need more than one number on it.

Example

1
const test1: MultiDigitNumberString = "01"; // ok
2
const test2: MultiDigitNumberString = "1"; // error

View source


NotEmpty<Type>

1
type NotEmpty<Type>: Exclude<Type, Empty>;

Type for a non-empty ArrayLike, object or string.

Remarks

This type is useful for cases where you want to ensure that a value is not empty. For example, if you have an array that should always have at least one element, you could type it as NotEmpty<ArrayLike<ElementType>>.

Example

1
const notEmptyString: NotEmpty<string> = "๐ŸŸข";
2
const notEmptyArray: NotEmpty<ReadOnlyArray> = ["๐ŸŸข", "๐ŸŸฉ"];
3
const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "๐ŸŸข": "๐ŸŸฉ" };

See

Empty

Type parameters

Type parameterDescription
Type extends ArrayLike | object | stringThe type to check.

View source


Tagger()<Output, Expressions>

1
type Tagger<Output, Expressions>: (templateStrings: TemplateStringsArray, ...expressions: Expressions) => Output;

Tag function for tagged templates.

Remarks

Type to represent a tag function for tagged templates, which takes a TemplateStringArray and any number of expressions, and returns a value of type Output (string by default).

Example

1
const intParser: Tagger<number> = strings => parseInt(strings.join(""), 10);
2
intParser`100`; // 100

See

ReadOnlyArray

Type parameters

Type parameterValueDescription
OutputstringType of the output value.
Expressions extends ReadOnlyArrayReadOnlyArrayType of the expressions.

Parameters

ParameterType
templateStringsTemplateStringsArray
โ€ฆexpressionsExpressions

Returns

Output

View source


Tail<Input>

1
type Tail<Input>: HeadAndTail<Input>[1];

Last values of an ArrayLike (omitting the first).

Remarks

Type of the last items of an ArrayLike, excluding the first item in said ArrayLike.

Example

1
const array = ["๐ŸŸข", "๐ŸŸฉ", "๐Ÿ’š"];
2
const tail: Tail<typeof array> = ["๐ŸŸฉ", "๐Ÿ’š"];

See

Type parameters

Type parameterDescription
Input extends ArrayLikeType of the array to get the tail.

View source