Types by Lou
π·οΈ Collection of TypeScript types shared across Lou Codes projects.
Usage
π¦ Node
Install @lou.codes/types
as a dependency:
pnpm add @lou.codes/types# ornpm install @lou.codes/types# oryarn add @lou.codes/types
Import as type and use it:
import type { Unary } from "@lou.codes/types";
π¦ Deno
Import @lou.codes/types
using the npm:
prefix, and use it directly:
import type { Unary } from "npm:@lou.codes/types";
Useful links
- π Documentation: TypeDoc generated documentation.
- β³ Changelog: List of changes between versions.
Array
ArrayLike
Ζ¬ ArrayLike<Item
>: Object
An alternative for TypeScriptβs ArrayLike
type, with its type set to unknown
by default.
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
const arrayLike: ArrayLike<number> = [1, 2, 3];
Type parameters
Name | Type | Description |
---|---|---|
Item | unknown | Type of the items in the array-like object. |
Index signature
βͺ [index: number
]: Item
Item of the ArrayLike.
Type declaration
Name | Type | Description |
---|---|---|
length | number | Amount of items in the ArrayLike. |
Empty
Ζ¬ Empty: EmptyArray
|
EmptyRecord
|
EmptyString
Empty array, object or string.
Remarks
Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.
Example
const emptyString: Empty = "";const emptyArray: Empty = [];const emptyRecord: Empty = {};
See
EmptyArray
Ζ¬ EmptyArray: readonly []
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
const emptyArray: EmptyArray = [];
Entry
Ζ¬ Entry<Key
, Value
>: readonly [key: Key, value: 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
const entry: Entry<string, number> = ["π’", 1];
Type parameters
Name | Type | Description |
---|---|---|
Key | PropertyKey | Objectβs properties type. |
Value | unknown | Objectβs values type. |
EntryKey
Ζ¬ EntryKey<Input
>: First
<Input
>
Key of an Entry.
Remarks
Util type to get the key of an Entry.
Example
const entry: Entry<string, number> = ["π’", 1];const entryKey: EntryKey<typeof entry> = entry[0];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends Entry | Entry type. |
EntryOf
Ζ¬ EntryOf<Input
>:
Entry
<KeyOf
<Input
>,
ValueOf
<Input
>>
Object or array Entry.
Remarks
Get the Entry type out of an object or array.
Example
const object = { "π’": 1, "π©": 2,};const entries: EntryOf<typeof object> = Object.entries(object)[0];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | Array or record type. |
EntryValue
Ζ¬ EntryValue<Input
>: Second
<Input
>
Value of an Entry.
Remarks
Util type to get the value of an Entry.
Example
const entry: Entry<string, number> = ["π’", 1];const entryValue: EntryValue<typeof entry> = entry[1];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends Entry | Entry type. |
First
Ζ¬ First<Input
>: Input
[0
]
First value of an ArrayLike.
Remarks
Type of the first item of an ArrayLike
, mainly here to avoid magic numbers.
Example
const array = ["π’", "π©", "π"];const first: First<typeof array> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
Head
Ζ¬ Head<Input
>:
First
<HeadAndTail
<Input
>>
Initial value of an ArrayLike
.
Remarks
Given a type argument (an ArrayLike
), this returns the type of the item in
index 0
.
Example
const array = ["π’", "π©", "π"];const head: Head<typeof array> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | ArrayLike value (such as Array or string ). |
HeadAndTail
Ζ¬ HeadAndTail<Input
>: Input
extends readonly [head: infer HeadItem,
tail: infer TailItems] ? readonly [head: HeadItem, tail: TailItems] : Input
extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [head:
FirstCharacter, tail: RestOfString] : Input
extends
EmptyArray
|
EmptyString
? readonly [head: undefined,
tail: Input] : readonly [head: Maybe<Input[number]>, tail: 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
const array = ["π’", "π©", "π"];const headAndTail: HeadAndTail<typeof array> = ["π’", ["π©", "π"]];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Input ArrayLike . |
Initial
Ζ¬ Initial<Input
>:
First
<InitialAndLast
<Input
>>
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
const array = ["π’", "π©", "π"];const initial: Initial<typeof array> = ["π’", "π©"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | ArrayLike value (such as Array or string ). |
InitialAndLast
Ζ¬ InitialAndLast<Input
>: Input
extends readonly [β¦(infer
InitialItems), infer LastItem] ? readonly [initial: InitialItems, last:
LastItem] : Input
extends EmptyArray
|
EmptyString
? readonly [initial: Input,
last: undefined] : Input
extends `${infer FirstCharacter}${infer
RestOfString}` ? readonly [initial: `${RestOfString extends EmptyString ?
EmptyString : FirstCharacter}${Head<InitialAndLast<RestOfString>>}`, last:
`${RestOfString extends EmptyString ? FirstCharacter :
Last<RestOfString>}`] : readonly [initial: Input, last:
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
const array = ["π’", "π©", "π"];const initialAndLast: InitialAndLast<typeof array> = [["π’", "π©"], "π"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Input ArrayLike . |
KeyOf
Ζ¬ KeyOf<Input
>: Input
extends
ArrayLike
?
NeverFallback
<Defined
<Exclude
<Partial
<Input
>["length"
],
Input
["length"
]>>, number
> : `${Exclude<keyof Input, symbol>}`
Generic key for either object or array.
Remarks
Type to represent the type of the key in an
ReadOnlyCollection. It automatically
omits symbol
keys from objects, and uses number
for arrays with dynamic
length
.
Example
const array = [1, 2, 3] as const;const object = { "π’": "π©" } as const;
const arrayKey: KeyOf<typeof array> = 0;const objectKey: KeyOf<typeof object> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | The input ReadOnlyCollection . |
Last
Ζ¬ Last<Input
>:
Second
<InitialAndLast
<Input
>>
Last value of an ArrayLike
.
Remarks
Type of the last character of a string or the last element of an array.
Example
const array = ["π’", "π©", "π"];const last: Last<typeof array> = "π";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
NotEmpty
Ζ¬ 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
const notEmptyString: NotEmpty<string> = "π’";const notEmptyArray: NotEmpty<ReadOnlyArray> = ["π’", "π©"];const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "π’": "π©" };
See
Type parameters
Name | Type | Description |
---|---|---|
Type | extends ArrayLike | object | string | The type to check. |
ReadOnly
Ζ¬ ReadOnly<Input
>: Input
extends Readonly
<ReadonlyMap
<infer Key,
infer Value>> ?
Readonly
<ReadonlyMap
<ReadOnly
<Key
>,
ReadOnly
<Value
>>> : Input
extends
Readonly
<ReadonlySet
<infer Item>> ?
Readonly
<ReadonlySet
<ReadOnly
<Item
>>>
: Input
extends readonly [] ? readonly [] : Input
extends readonly [infer
Head, β¦(infer Tail)] ? readonly
[ReadOnly
<Head
>, β¦ReadOnly<Tail>] :
Input
extends ReadonlyArray
<infer Item> ?
ReadonlyArray
<ReadOnly
<Item
>> : Input
extends Function
? Input
: Input
extends object
? { readonly [Property
in keyof Input]: ReadOnly<Input[Property]> } : Input
Read-only deep any Input
.
Remarks
This type makes any Input
read-only recursively, including nested objects and
arrays, Sets, Maps, and functions.
Example
const record: ReadOnly<Record<string, Array<number>>> = { "π’": [1, 2, 3], "π©": [4, 5, 6],};record["π’"][0] = 7; // Error
Type parameters
Name | Description |
---|---|
Input | The type to make read-only. |
ReadOnlyArray
Ζ¬ ReadOnlyArray<Item
>:
ReadOnly
<Item
[]>
Read-only array.
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
, plus
it recursively makes all the items in the array read-only.
Example
const array: ReadOnlyArray<{ "π’": number }> = [{ "π’": 1 }, { "π’": 2 }];array[0]["π’"] = 3; // Error
See
Type parameters
Name | Type | Description |
---|---|---|
Item | unknown | Type of the items in the array. |
ReadOnlyCollection
Ζ¬ ReadOnlyCollection<Item
>:
ArrayLike
<Item
> |
ReadOnlyRecord
<PropertyKey
, Item
>
Read-only collection (ArrayLike or ReadOnlyRecord).
Remarks
Read-only type union of ArrayLike or ReadOnlyRecord.
Example
const record: ReadOnly<Record<string, Array<number>>> = { "π’": [1, 2, 3], "π©": [4, 5, 6],};record["π’"][0] = 7; // Error
See
Type parameters
Name | Type | Description |
---|---|---|
Item | unknown | Type of the items in the collection. |
Reducer
Ζ¬ 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
const reducer: Reducer<number, number> = item => accumulator => accumulator + item;
See
Type parameters
Name | Description |
---|---|
Item | Type of the items to reduce. |
Accumulator | Type of the accumulator/output. |
Second
Ζ¬ Second<Input
>: Input
[1
]
Second value of an ArrayLike.
Remarks
Type of the Second item of an ArrayLike
, manly here to avoid magic numbers.
Example
const array = ["π’", "π©", "π"];const second: Second<typeof array> = "π©";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
Sorter
Ζ¬ Sorter<Item
>: Unary
<Item
,
Unary
<Item
, number
>>
Curried sorter Unary function.
Remarks
Type to represent a function that takes two items and returns a number to determine their order. If the result is negative, the first item is sorted before the second item. If the result is positive, the first item is sorted after the second item. If the result is zero, the order of the items is unchanged.
Example
const sorter: Sorter<number> = value1 => value2 => value1 - value2;
See
Type parameters
Name | Description |
---|---|
Item | Type of the items to sort. |
Tail
Ζ¬ Tail<Input
>:
Second
<HeadAndTail
<Input
>>
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
const array = ["π’", "π©", "π"];const tail: Tail<typeof array> = ["π©", "π"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Type of the array to get the tail. |
ValueOf
Ζ¬ ValueOf<Input
>: Input
[KeyOf
<Input
>
& keyof Input
]
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
const object = { "π’": 1, "π©": 2,};const key: ValueOf<typeof object> = 1;
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | Type of the collection. |
Common
Awaitable
Ζ¬ Awaitable<Type
>: Promise
<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
type AwaitableString = Awaitable<string>;const promisedValue: AwaitableString = Promise.resolve("π’");const plainValue: AwaitableString = "π©";
Promise.all([promisedValue, plainValue]).then(console.log); // ["π’", "π©"]
See
Type parameters
Name | Type | Description |
---|---|---|
Type | unknown | The type to await. |
Defined
Ζ¬ Defined<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
const maybeUndefined: string | undefined = "π’";const definitelyDefined: Defined<typeof maybeUndefined> = "π’";
See
Type parameters
Name |
---|
Input |
Falsy
Ζ¬ Falsy: EmptyString
|
HTMLAllCollection
| Nullish
| 0
| 0n
|
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
const falsyBoolean: Falsy = false;const falsyHTMLAllCollection: Falsy = document.all;const falsyNegativeZero: Falsy = -0;const falsyNegativeZeroBigInt: Falsy = -0n;const falsyNull: Falsy = null;const falsyString: Falsy = "";const falsyUndefined: Falsy = undefined;const falsyZero: Falsy = 0;const falsyZeroBigInt: Falsy = 0n;
See
JSONValue
Ζ¬ JSONValue: Exclude
<Primitive
,
bigint
| symbol
| undefined
> |
ReadonlyArray
<JSONValue
> | {
[property: string]
: JSONValue
; }
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
const json: JSONValue = JSON.parse('{"foo": "bar"}');
See
LocaleIdentifier
Ζ¬ LocaleIdentifier: "eo"
| "yue-Hant-HK"
|
`af${EmptyString | β-NAβ | β-ZAβ}` | `ak${EmptyString | β-GHβ}` |
`am${EmptyString | β-ETβ}` | `ar${EmptyString | β-AEβ | β-BHβ | β-DZβ
| β-EGβ | β-EHβ | β-ERβ | β-ILβ | β-IQβ | β-JOβ | β-KWβ | β-LBβ | β-LYβ
| β-MAβ | β-MRβ | β-OMβ | β-PSβ | β-QAβ | β-SAβ | β-SDβ | β-SOβ | β-SSβ
| β-SYβ | β-TDβ | β-TNβ | β-YEβ}` |
`as${EmptyString | β-INβ}` | `asa${EmptyString | β-TZβ}` |
`az${EmptyString | `-Cyrl${EmptyString | β-AZβ}` |
`-Latn${EmptyString | β-AZβ}`}` | `be${EmptyString | β-BYβ}` |
`bem${EmptyString | β-ZMβ}` | `bez${EmptyString | β-TZβ}` |
`bg${EmptyString | β-BGβ}` | `bm${EmptyString | β-MLβ}` |
`bn${EmptyString | β-BDβ | β-INβ}` | `bo${EmptyString | β-CNβ |
β-INβ}` | `bs${EmptyString | β-BAβ}` | `ca${EmptyString | β-ESβ}` |
`cgg${EmptyString | β-UGβ}` | `chr${EmptyString | β-USβ}` |
`cs${EmptyString | β-CZβ}` | `cy${EmptyString | β-GBβ}` |
`da${EmptyString | β-DKβ}` | `dav${EmptyString | β-KEβ}` |
`de${EmptyString | β-ATβ | β-BEβ | β-CHβ | β-DEβ | β-LIβ | β-LUβ}` | `ebu${EmptyString
| β-KEβ}` | `ee${EmptyString | β-GHβ | β-TGβ}` | `el${EmptyString |
β-CYβ | β-GRβ}` |
`en${EmptyString | β-ASβ | β-AUβ | β-BEβ | β-BWβ | β-BZβ | β-CAβ | β-GBβ | β-GUβ | β-HKβ | β-IEβ | β-ILβ | β-INβ | β-JMβ | β-MHβ | β-MPβ | β-MTβ | β-MUβ | β-NAβ | β-NZβ | β-PHβ | β-PKβ | β-SGβ | β-TTβ | β-UMβ | β-USβ | β-VIβ | β-ZAβ | β-ZWβ}` | `es${EmptyString
| β-419β | β-ARβ | β-BOβ | β-CLβ | β-COβ | β-CRβ | β-DOβ | β-ECβ |
β-ESβ | β-GQβ | β-GTβ | β-HNβ | β-MXβ | β-NIβ | β-PAβ | β-PEβ | β-PRβ |
β-PYβ | β-SVβ | β-USβ | β-UYβ | β-VEβ}` |
`et${EmptyString | β-EEβ}` | `eu${EmptyString | β-ESβ}` |
`fa${EmptyString | β-AFβ | β-IRβ}` | `ff${EmptyString | β-SNβ}` |
`fi${EmptyString | β-FIβ}` | `fil${EmptyString | β-PHβ}` |
`fo${EmptyString | β-FOβ}` | `fr${EmptyString | β-BEβ | β-BFβ | β-BIβ
| β-BJβ | β-BLβ | β-CAβ | β-CDβ | β-CFβ | β-CGβ | β-CHβ | β-CIβ | β-CMβ
| β-DJβ | β-FRβ | β-GAβ | β-GNβ | β-GPβ | β-GQβ | β-KMβ | β-LUβ | β-MCβ
| β-MFβ | β-MGβ | β-MLβ | β-MQβ | β-NEβ | β-REβ | β-RWβ | β-SNβ | β-TDβ
| β-TGβ}` | `ga${EmptyString | β-IEβ}` | `gl${EmptyString | β-ESβ}`
| `gsw${EmptyString | β-CHβ}` | `gu${EmptyString | β-INβ}` |
`guz${EmptyString | β-KEβ}` | `gv${EmptyString | β-GBβ}` |
`ha${EmptyString | `-Latn${EmptyString | β-GHβ | β-NEβ | β-NGβ}`}` |
`haw${EmptyString | β-USβ}` | `he${EmptyString | β-ILβ}` |
`hi${EmptyString | β-INβ}` | `hr${EmptyString | β-HRβ}` |
`hu${EmptyString | β-HUβ}` | `hy${EmptyString | β-AMβ}` |
`id${EmptyString | β-IDβ}` | `ig${EmptyString | β-NGβ}` |
`ii${EmptyString | β-CNβ}` | `is${EmptyString | β-ISβ}` |
`it${EmptyString | β-CHβ | β-ITβ}` | `ja${EmptyString | β-JPβ}` |
`jmc${EmptyString | β-TZβ}` | `ka${EmptyString | β-GEβ}` |
`kab${EmptyString | β-DZβ}` | `kam${EmptyString | β-KEβ}` |
`kde${EmptyString | β-TZβ}` | `kea${EmptyString | β-CVβ}` |
`khq${EmptyString | β-MLβ}` | `ki${EmptyString | β-KEβ}` |
`kk${EmptyString | `-Cyrl${EmptyString | β-KZβ}`}` |
`kl${EmptyString | β-GLβ}` | `kln${EmptyString | β-KEβ}` |
`km${EmptyString | β-KHβ}` | `kn${EmptyString | β-INβ}` |
`ko${EmptyString | β-KRβ}` | `kok${EmptyString | β-INβ}` |
`kw${EmptyString | β-GBβ}` | `lag${EmptyString | β-TZβ}` |
`lg${EmptyString | β-UGβ}` | `lt${EmptyString | β-LTβ}` |
`luo${EmptyString | β-KEβ}` | `luy${EmptyString | β-KEβ}` |
`lv${EmptyString | β-LVβ}` | `mas${EmptyString | β-KEβ | β-TZβ}` |
`mer${EmptyString | β-KEβ}` | `mfe${EmptyString | β-MUβ}` |
`mg${EmptyString | β-MGβ}` | `mk${EmptyString | β-MKβ}` |
`ml${EmptyString | β-INβ}` | `mr${EmptyString | β-INβ}` |
`ms${EmptyString | β-BNβ | β-MYβ}` | `mt${EmptyString | β-MTβ}` |
`my${EmptyString | β-MMβ}` | `naq${EmptyString | β-NAβ}` |
`nb${EmptyString | β-NOβ}` | `nd${EmptyString | β-ZWβ}` |
`ne${EmptyString | β-INβ | β-NPβ}` | `nl${EmptyString | β-BEβ |
β-NLβ}` | `nn${EmptyString | β-NOβ}` | `nyn${EmptyString | β-UGβ}` |
`om${EmptyString | β-ETβ | β-KEβ}` | `or${EmptyString | β-INβ}` |
`pa${EmptyString | `-Arab${EmptyString | β-PKβ}` |
`-Guru${EmptyString | β-INβ}`}` | `pl${EmptyString | β-PLβ}` |
`ps${EmptyString | β-AFβ}` | `pt${EmptyString | β-BRβ | β-GWβ | β-MZβ
| β-PTβ}` | `rm${EmptyString | β-CHβ}` | `ro${EmptyString | β-MDβ |
β-ROβ}` | `rof${EmptyString | β-TZβ}` | `ru${EmptyString | β-MDβ |
β-RUβ | β-UAβ}` | `rw${EmptyString | β-RWβ}` | `rwk${EmptyString |
β-TZβ}` | `saq${EmptyString | β-KEβ}` | `seh${EmptyString | β-MZβ}`
| `ses${EmptyString | β-MLβ}` | `sg${EmptyString | β-CFβ}` |
`shi${EmptyString | `-Latn${EmptyString | β-MAβ}` |
`-Tfng${EmptyString | β-MAβ}`}` | `si${EmptyString | β-LKβ}` |
`sk${EmptyString | β-SKβ}` | `sl${EmptyString | β-SIβ}` |
`sn${EmptyString | β-ZWβ}` | `so${EmptyString | β-DJβ | β-ETβ | β-KEβ
| β-SOβ}` | `sq${EmptyString | β-ALβ}` | `sr${EmptyString |
`-Cyrl${EmptyString | β-BAβ | β-MEβ | β-RSβ}` | `-Latn${EmptyString |
β-BAβ | β-MEβ | β-RSβ}`}` |
`sv${EmptyString | β-FIβ | β-SEβ}` | `sw${EmptyString | β-KEβ |
β-TZβ}` | `ta${EmptyString | β-INβ | β-LKβ}` | `te${EmptyString |
β-INβ}` | `teo${EmptyString | β-KEβ | β-UGβ}` | `th${EmptyString |
β-THβ}` | `ti${EmptyString | β-ERβ | β-ETβ}` | `to${EmptyString |
β-TOβ}` | `tr${EmptyString | β-TRβ}` | `tzm${EmptyString |
`-Latn${EmptyString | β-MAβ}`}` | `uk${EmptyString | β-UAβ}` |
`ur${EmptyString | β-INβ | β-PKβ}` | `uz${EmptyString |
`-Arab${EmptyString | β-AFβ}` | `-Cyrl${EmptyString | β-UZβ}` |
`-Latn${EmptyString | β-UZβ}`}` | `vi${EmptyString | β-VNβ}` |
`vun${EmptyString | β-TZβ}` | `xog${EmptyString | β-UGβ}` |
`yo${EmptyString | β-NGβ}` | `zh${EmptyString |
`-Hans${EmptyString | β-CNβ | β-HKβ | β-MOβ | β-SGβ}` | `-Hant${EmptyString
| β-HKβ | β-MOβ | β-TWβ}`}` | `zu${EmptyString | β-ZAβ}`
Locale identifiers (language-country).
Remarks
When using i18n tools, this is a stricter union type than string
to handle the
locale identifiers.
Example
const locale: LocaleIdentifier = "en-US";
See
Maybe
Ζ¬ Maybe<Value
>: Value
| 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
type MaybeNumber = Maybe<number>;const maybeNumber: MaybeNumber = 1;const notNumber: MaybeNumber = undefined;
Type parameters
Name | Description |
---|---|
Value | The type of the value to make optional. |
NeverFallback
Ζ¬ 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
const value: never = undefined as never;NeverFallback<typeof value, number>; // Will be number
Type parameters
Name | Description |
---|---|
MaybeNever | The type that may or may not be never . |
Fallback | The fallback type to use if MaybeNever is never . |
Nullish
Ζ¬ 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
const nullishUndefined: Nullish = undefined;const nullishNull: Nullish = null;
See
Primitive
Ζ¬ Primitive: Nullish
|
Numeric
| boolean
| string
| 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
const aBigInt: Primitive = 13n;const aBoolean: Primitive = true;const aNull: Primitive = null;const aNumber: Primitive = 13;const anUndefined: Primitive = undefined;const aString: Primitive = "π’";const aSymbol: Primitive = Symbol("π’");
See
ReplaceType
Ζ¬ ReplaceType<Type
, Keys
, NewType
>:
ReadOnly
<Omit
<Type
, Keys
>> &
ReadOnlyRecord
<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
type User = { name: string; age: number };type ReallyOldUser = ReplaceType<User, "age", bigint>;
See
Type parameters
Name | Type | Description |
---|---|---|
Type | extends object | Type to replace the type of some keys in. |
Keys | extends keyof Type | Keys to replace the type of. |
NewType | NewType | New type to replace the old type with. |
Single
Ζ¬ Single<Type
>: readonly [single: 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
const single: Single<boolean> = [true];
Type parameters
Name | Description |
---|---|
Type | Type of the single element. |
Strigifiable
Ζ¬ 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
let value: Strigifiable = "hello";value = 1;value = true;value = Symbol("hello"); // Error!value = { toString: () => "hello" }; // Error!
See
Truthy
Ζ¬ 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
Truthy<"" | "truthy">; // "truthy"
See
Type parameters
Name | Type | Description |
---|---|---|
Type | unknown | Type to exclude Falsy values from. |
TypeOfDictionary
Ζ¬ TypeOfDictionary: Object
typeof
dictionary.
Remarks
Dictionary of types and their typeof
values, including the proposed but never
added type "null"
for null
.
Example
TypeOfMap["string"]; // `string`TypeOfMap["boolean"]; // `boolean`TypeOfMap["function"]; // `GenericFunction`
See
Type declaration
Name | Type | Description |
---|---|---|
bigint | bigint | TypeOfDictionary key for BigInt |
boolean | boolean | TypeOfDictionary key for Boolean |
function | Function | TypeOfDictionary key for Function |
null | null | TypeOfDictionary key for null |
number | number | TypeOfDictionary key for Number |
object | object | TypeOfDictionary key for Object |
string | string | TypeOfDictionary key for String |
symbol | symbol | TypeOfDictionary key for Symbol |
undefined | undefined | TypeOfDictionary key for undefined |
TypeOfValue
Ζ¬ 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
const typeString: TyeOfValue = "string";const typeBoolean: TyeOfValue = "boolean";const typeFunction: TyeOfValue = "function";
See
Date
DayOfMonth
Ζ¬ 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
const days: Iterable<DayOfMonth> = [1, 2, 3, 28, 29, 30, 31];
See
DayOfWeek
Ζ¬ 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
const daysOfWeek: Iterable<DayOfWeek> = [0, 1, 2, 3, 4, 5, 6];
See
Hours
Ζ¬ 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
const hours: Iterable<Hours> = [0, 1, 2, 3, 20, 21, 22, 23];
See
ISODate
Ζ¬ ISODate: `${ISOYear}-${ISOMonth}-${ISODayOfMonth}T${bigint}${bigint}:${bigint}${bigint}:${bigint}${bigint}.${bigint}${bigint}${bigint}Z`
String representing an ISO date.
Remarks
This type is a string representing an ISO 8601 format of a date (returned by
Date.prototype.toISOString
).
Example
const date: ISODate = "2020-01-01T00:00:00.000Z";
See
ISODayOfMonth
Ζ¬ 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
const days: Iterable<ISODayOfMonth> = ["01", "15", "31"];
See
ISOHours
Ζ¬ 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
const hours: Iterable<ISOHours> = ["00", "06", "23"];
See
ISOMilliseconds
Ζ¬ 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
const milliseconds: Iterable<ISOMilliseconds> = ["001", "250", "999"];
See
ISOMinutes
Ζ¬ 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
const minutes: Iterable<ISOMinutes> = ["00", "30", "59"];
See
ISOMonth
Ζ¬ 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
const months: Iterable<ISOMonth> = ["01", "06", "12"];
See
ISOSeconds
Ζ¬ 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
const seconds: Iterable<ISOSeconds> = ["00", "30", "59"];
See
ISOYear
Ζ¬ ISOYear: `${EmptyString | β-β}${number}`
ISO year values in string format (from "-271821"
to "275760"
).
Remarks
Stricter than string
type for year values, limited to valid values from
"-271821"
to "275760"
, and giving type errors otherwise.
Example
const years: Iterable<ISOYear> = ["2020", "-1000", "1989"];
See
Milliseconds
Ζ¬ 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
const milliseconds: Iterable<Milliseconds> = [1, 250, 999];
See
Minutes
Ζ¬ 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
const minutes: Iterable<Minutes> = [0, 30, 59];
See
Month
Ζ¬ 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
const months: Iterable<ISOMonth> = [1, 6, 11];
See
Seconds
Ζ¬ 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
const seconds: Iterable<Seconds> = [0, 30, 59];
See
Function
Class
Ζ¬ Class<Arguments
, Instance
>: (β¦classArguments
: Arguments
) =>
Instance
Type parameters
Name | Type | Description |
---|---|---|
Arguments | extends ReadOnlyArray = ReadOnlyArray | Arguments of the class constructor. |
Instance | unknown | Instance of the class. |
Type declaration
β’ (...classArguments
): Instance
A generic type for classes.
Parameters
Name | Type | Description |
---|---|---|
...classArguments | Arguments | Arguments of the class constructor. |
Returns
Instance
Instance of the class.
Remarks
This type is a generic constructor function, mainly used when wrapping classes.
Example
const example = (AClass: Class) => new AClass("test");
See
Comparison
Ζ¬ Comparison<Right
, Left
, Predicated
>:
Unary
<Right
,
Single
<Predicated
> extends
Single
<never
> ?
Filter
<Left
> :
Predicate
<Left
, Predicated
>>
Comparison curried function.
Remarks
Curried function that takes a Right
and a Left
value and returns a boolean
representing a comparison between them.
Example
const biggerThan: Comparison<number> = right => left => right > left;
See
Param
Right-hand side of the comparison.
Type parameters
Name | Type | Description |
---|---|---|
Right | unknown | Right-hand side of the comparison. |
Left | extends Right = Right | Left-hand side of the comparison. |
Predicated | extends Left = never | Type of the value if Predicate returns true . |
Filter
Ζ¬ 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
const isEven: Filter<number> = number => number % 2 === 0;
See
Param
The input value to check.
Type parameters
Name | Description |
---|---|
Input | The type of the input value. |
Function
Ζ¬ Function<Arguments
, Output
>: (β¦input
: Arguments
) => Output
Type parameters
Name | Type | Description |
---|---|---|
Arguments | extends ReadOnlyArray = ReadOnlyArray | Arguments of the function. |
Output | unknown | Output of the function. |
Type declaration
βΈ (...input
): Output
Generic function type (safer than using any
).
Parameters
Name | Type |
---|---|
...input | Arguments |
Returns
Output
Output of the function.
Remarks
This type is a generic function type, for callbacks and other places where any type of function can be received.
Example
const example = (callback: Function) => callback("test");
See
Predicate
Ζ¬ Predicate<Input
, Predicated
>: (input
: Input
) => input is
Predicated
Type parameters
Name | Type | Description |
---|---|---|
Input | Input | The type of the input value. |
Predicated | extends Input = Input | The subset of Input for which the predicate holds. |
Type declaration
βΈ (input
): input is Predicated
Unary function that returns a boolean
and infers a given type for its
argument.
Parameters
Name | Type | Description |
---|---|---|
input | Input | The input value to check. |
Returns
input is Predicated
true
if the predicate holds for the input value, and false
otherwise.
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
const isString: Predicate<number | string, string> = ( numberOrString,): numberOrString is string => typeof numberOrString === "string";
See
ReadOnlyArguments
Ζ¬ 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
const example = (_foo: string, _bar: number) => undefined;type ExampleArguments = ReadOnlyArguments<typeof example>; // readonly [string, number]
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends Function <ReadOnlyArray <never >> | Function to extract parameters from. |
Reducer
Ζ¬ 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
const reducer: Reducer<number, number> = item => accumulator => accumulator + item;
See
Type parameters
Name | Description |
---|---|
Item | Type of the items to reduce. |
Accumulator | Type of the accumulator/output. |
Sorter
Ζ¬ Sorter<Item
>: Unary
<Item
,
Unary
<Item
, number
>>
Curried sorter Unary function.
Remarks
Type to represent a function that takes two items and returns a number to determine their order. If the result is negative, the first item is sorted before the second item. If the result is positive, the first item is sorted after the second item. If the result is zero, the order of the items is unchanged.
Example
const sorter: Sorter<number> = value1 => value2 => value1 - value2;
See
Type parameters
Name | Description |
---|---|
Item | Type of the items to sort. |
Tagger
Ζ¬ Tagger<Output
, Expressions
>:
Function
<readonly [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
const intParser: Tagger<number> = strings => parseInt(strings.join(""), 10);intParser`100`; // 100
See
Type parameters
Name | Type | Description |
---|---|---|
Output | string | Type of the output value. |
Expressions | extends ReadOnlyArray = ReadOnlyArray | Type of the expressions. |
Unary
Ζ¬ Unary<Input
, Output
>:
Function
<Single
<Input
>,
Output
>
Unary function.
Remarks
Type to represent a function that takes a single argument, ideal for currying.
Example
const unary: Unary<number, number> = number => number + 1;
See
Type parameters
Name | Description |
---|---|
Input | Type of the input value. |
Output | Type of the output value. |
UnaryInput
Ζ¬ 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
const unary: Unary<number, string> = number => `${number}`;UnaryInput<typeof unary>; // `number`
See
Type parameters
Name | Type | Description |
---|---|---|
UnaryFunction | extends Unary <never , unknown > | Type of the unary function to get the input type of. |
UnaryOutput
Ζ¬ 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
const unary: Unary<number, string> = number => `${number}`;UnaryOutput<typeof unary>; // `string`
See
Type parameters
Name | Type | Description |
---|---|---|
UnaryFunction | extends Unary <never , unknown > | Type of the unary function to get the output type of. |
HTML
HTMLElementTagAttributeMap
Ζ¬ HTMLElementTagAttributeMap:
ReadOnlyRecord
<`${string}-${string}`,
HTMLElementTagGlobalAttributes
>
& { a
:
HTMLElementTagGlobalAttributes
& { download?
: string
; href?
: string
; hreflang?
: string
;
ping?
: string
; referrerpolicy?
: string
; rel?
: string
; target?
:
string
; type?
: string
} ; abbr
:
HTMLElementTagGlobalAttributes
; address
:
HTMLElementTagGlobalAttributes
; area
:
HTMLElementTagGlobalAttributes
& { accesskey?
: string
; alt?
: string
; coords?
: string
;
download?
: string
; href?
: string
; hreflang?
: string
; ping?
:
string
; rel?
: string
; shape?
: string
; target?
: string
;
type?
: string
} ; article
:
HTMLElementTagGlobalAttributes
; aside
:
HTMLElementTagGlobalAttributes
; audio
:
HTMLElementTagGlobalAttributes
& { autoplay?
: string
; controls?
: string
; crossorigin?
: string
;
loop?
: string
; mediagroup?
: string
; muted?
: string
; preload?
:
string
; src?
: string
} ; b
:
HTMLElementTagGlobalAttributes
; base
:
HTMLElementTagGlobalAttributes
& { href?
: string
; target?
: string
} ; bdi
:
HTMLElementTagGlobalAttributes
; bdo
:
HTMLElementTagGlobalAttributes
& { dir?
: string
} ; blockquote
:
HTMLElementTagGlobalAttributes
& { cite?
: string
} ; body
:
HTMLElementTagGlobalAttributes
& { alink?
: string
; background?
: string
; bgcolor?
: string
;
bottommargin?
: string
; leftmargin?
: string
; link?
: string
;
onafterprint?
: string
; onbeforeprint?
: string
; onbeforeunload?
:
string
; onblur?
: string
; onerror?
: string
; onfocus?
: string
;
onhashchange?
: string
; onlanguagechange?
: string
; onload?
: string
; onmessage?
: string
; onoffline?
: string
; ononline?
: string
;
onpagehide?
: string
; onpageshow?
: string
; onpopstate?
: string
;
onredo?
: string
; onresize?
: string
; onstorage?
: string
;
onundo?
: string
; onunload?
: string
; rightmargin?
: string
;
text?
: string
; topmargin?
: string
; vlink?
: string
} ; br
:
HTMLElementTagGlobalAttributes
& { clear?
: string
} ; button
:
HTMLElementTagGlobalAttributes
& { autocomplete?
: string
; autofocus?
: string
; disabled?
: string
; form?
: string
; formaction?
: string
; formenctype?
: string
;
formmethod?
: string
; formnovalidate?
: string
; formtarget?
: string
; name?
: string
; type?
: string
; value?
: string
} ; canvas
:
HTMLElementTagGlobalAttributes
& { height?
: string
; moz-opaque?
: string
; width?
: string
} ;
caption
:
HTMLElementTagGlobalAttributes
& { align?
: string
} ; cite
:
HTMLElementTagGlobalAttributes
; code
:
HTMLElementTagGlobalAttributes
; col
:
HTMLElementTagGlobalAttributes
& { align?
: string
; span?
: string
} ; colgroup
:
HTMLElementTagGlobalAttributes
& { align?
: string
; span?
: string
} ; data
:
HTMLElementTagGlobalAttributes
& { value?
: string
} ; datalist
:
HTMLElementTagGlobalAttributes
; dd
:
HTMLElementTagGlobalAttributes
& { nowrap?
: string
} ; del
:
HTMLElementTagGlobalAttributes
& { cite?
: string
; datetime?
: string
} ; details
:
HTMLElementTagGlobalAttributes
& { open?
: string
} ; dfn
:
HTMLElementTagGlobalAttributes
; dialog
:
HTMLElementTagGlobalAttributes
& { open?
: string
} ; div
:
HTMLElementTagGlobalAttributes
; dl
:
HTMLElementTagGlobalAttributes
; dt
:
HTMLElementTagGlobalAttributes
; em
:
HTMLElementTagGlobalAttributes
; embed
:
HTMLElementTagGlobalAttributes
& { height?
: string
; src?
: string
; type?
: string
; width?
:
string
} ; fieldset
:
HTMLElementTagGlobalAttributes
& { disabled?
: string
; form?
: string
; name?
: string
} ;
figcaption
:
HTMLElementTagGlobalAttributes
; figure
:
HTMLElementTagGlobalAttributes
; footer
:
HTMLElementTagGlobalAttributes
; form
:
HTMLElementTagGlobalAttributes
& { accept?
: string
; accept-charset?
: string
; action?
: string
;
autocapitalize?
: string
; autocomplete?
: string
; enctype?
: string
;
method?
: string
; name?
: string
; novalidate?
: string
; target?
:
string
} ; h1
:
HTMLElementTagGlobalAttributes
; h2
:
HTMLElementTagGlobalAttributes
; h3
:
HTMLElementTagGlobalAttributes
; h4
:
HTMLElementTagGlobalAttributes
; h5
:
HTMLElementTagGlobalAttributes
; h6
:
HTMLElementTagGlobalAttributes
; head
:
HTMLElementTagGlobalAttributes
& { profile?
: string
} ; header
:
HTMLElementTagGlobalAttributes
; hgroup
:
HTMLElementTagGlobalAttributes
; hr
:
HTMLElementTagGlobalAttributes
& { align?
: string
; color?
: string
; noshade?
: string
; size?
:
string
; width?
: string
} ; html
:
HTMLElementTagGlobalAttributes
& { manifest?
: string
; version?
: string
; xmlns?
: string
} ; i
:
HTMLElementTagGlobalAttributes
; iframe
:
HTMLElementTagGlobalAttributes
& { allow?
: string
; allowfullscreen?
: string
; allowpaymentrequest?
:
string
; csp?
: string
; height?
: string
; importance?
: string
;
name?
: string
; referrerpolicy?
: string
; sandbox?
: string
;
seamless?
: string
; src?
: string
; srcdoc?
: string
; width?
:
string
} ; img
:
HTMLElementTagGlobalAttributes
& { alt?
: string
; crossorigin?
: string
; decoding?
: string
;
height?
: string
; importance?
: string
; intrinsicsize?
: string
;
ismap?
: string
; loading?
: string
; referrerpolicy?
: string
;
sizes?
: string
; src?
: string
; srcset?
: string
; usemap?
:
string
; width?
: string
} ; input
:
HTMLElementTagGlobalAttributes
& { accept?
: string
; alt?
: string
; autocomplete?
: string
;
autofocus?
: string
; checked?
: string
; dirname?
: string
;
disabled?
: string
; form?
: string
; formaction?
: string
;
formenctype?
: string
; formmethod?
: string
; formnovalidate?
: string
; formtarget?
: string
; height?
: string
; inputmode?
: string
;
list?
: string
; max?
: string
; maxlength?
: string
; min?
: string
; minlength?
: string
; multiple?
: string
; name?
: string
;
pattern?
: string
; placeholder?
: string
; readonly?
: string
;
required?
: string
; size?
: string
; src?
: string
; step?
: string
; type?
: string
; value?
: string
; width?
: string
} ; ins
:
HTMLElementTagGlobalAttributes
& { cite?
: string
; datetime?
: string
} ; kbd
:
HTMLElementTagGlobalAttributes
; label
:
HTMLElementTagGlobalAttributes
& { for?
: string
; form?
: string
} ; legend
:
HTMLElementTagGlobalAttributes
; li
:
HTMLElementTagGlobalAttributes
& { type?
: string
; value?
: string
} ; link
:
HTMLElementTagGlobalAttributes
& { as?
: string
; crossorigin?
: string
; href?
: string
;
hreflang?
: string
; importance?
: string
; integrity?
: string
;
media?
: string
; referrerpolicy?
: string
; rel?
: string
; sizes?
:
string
; title?
: string
; type?
: string
} ; main
:
HTMLElementTagGlobalAttributes
; map
:
HTMLElementTagGlobalAttributes
& { name?
: string
} ; mark
:
HTMLElementTagGlobalAttributes
; menu
:
HTMLElementTagGlobalAttributes
; meta
:
HTMLElementTagGlobalAttributes
& { charset?
: string
; content?
: string
; http-equiv?
: string
;
name?
: string
; scheme?
: string
} ; meter
:
HTMLElementTagGlobalAttributes
& { form?
: string
; high?
: string
; low?
: string
; max?
: string
; min?
: string
; optimum?
: string
; value?
: string
} ; nav
:
HTMLElementTagGlobalAttributes
; noscript
:
HTMLElementTagGlobalAttributes
; object
:
HTMLElementTagGlobalAttributes
& { archive?
: string
; border?
: string
; classid?
: string
;
codebase?
: string
; codetype?
: string
; data?
: string
; declare?
:
string
; form?
: string
; height?
: string
; name?
: string
;
standby?
: string
; tabindex?
: string
; type?
: string
;
typemustmatch?
: string
; usemap?
: string
; width?
: string
} ; ol
:
HTMLElementTagGlobalAttributes
& { compact?
: string
; reversed?
: string
; start?
: string
;
type?
: string
} ; optgroup
:
HTMLElementTagGlobalAttributes
& { disabled?
: string
; label?
: string
} ; option
:
HTMLElementTagGlobalAttributes
& { disabled?
: string
; label?
: string
; selected?
: string
;
value?
: string
} ; output
:
HTMLElementTagGlobalAttributes
& { for?
: string
; form?
: string
; name?
: string
} ; p
:
HTMLElementTagGlobalAttributes
; param
:
HTMLElementTagGlobalAttributes
& { name?
: string
; type?
: string
; value?
: string
; valuetype?
:
string
} ; picture
:
HTMLElementTagGlobalAttributes
; pre
:
HTMLElementTagGlobalAttributes
& { cols?
: string
; width?
: string
; wrap?
: string
} ; progress
:
HTMLElementTagGlobalAttributes
& { max?
: string
; value?
: string
} ; q
:
HTMLElementTagGlobalAttributes
& { cite?
: string
} ; rb
:
HTMLElementTagGlobalAttributes
; rp
:
HTMLElementTagGlobalAttributes
; rt
:
HTMLElementTagGlobalAttributes
; ruby
:
HTMLElementTagGlobalAttributes
; s
:
HTMLElementTagGlobalAttributes
; samp
:
HTMLElementTagGlobalAttributes
; script
:
HTMLElementTagGlobalAttributes
& { async?
: string
; charset?
: string
; crossorigin?
: string
;
defer?
: string
; integrity?
: string
; nomodule?
: string
; nonce?
:
string
; referrerpolicy?
: string
; src?
: string
; text?
: string
;
type?
: string
} ; section
:
HTMLElementTagGlobalAttributes
; select
:
HTMLElementTagGlobalAttributes
& { autocomplete?
: string
; autofocus?
: string
; disabled?
: string
; form?
: string
; multiple?
: string
; name?
: string
; required?
:
string
; size?
: string
} ; slot
:
HTMLElementTagGlobalAttributes
& { name?
: string
} ; small
:
HTMLElementTagGlobalAttributes
; source
:
HTMLElementTagGlobalAttributes
& { media?
: string
; sizes?
: string
; src?
: string
; srcset?
:
string
; type?
: string
} ; span
:
HTMLElementTagGlobalAttributes
; strong
:
HTMLElementTagGlobalAttributes
; style
:
HTMLElementTagGlobalAttributes
& { media?
: string
; nonce?
: string
; scoped?
: string
; title?
:
string
; type?
: string
} ; sub
:
HTMLElementTagGlobalAttributes
; summary
:
HTMLElementTagGlobalAttributes
; sup
:
HTMLElementTagGlobalAttributes
; table
:
HTMLElementTagGlobalAttributes
& { align?
: string
; border?
: string
} ; tbody
:
HTMLElementTagGlobalAttributes
& { align?
: string
} ; td
:
HTMLElementTagGlobalAttributes
& { abbr?
: string
; align?
: string
; axis?
: string
; bgcolor?
:
string
; colspan?
: string
; headers?
: string
; rowspan?
: string
}
; template
:
HTMLElementTagGlobalAttributes
; textarea
:
HTMLElementTagGlobalAttributes
& { autocapitalize?
: string
; autocomplete?
: string
; autofocus?
:
string
; cols?
: string
; dirname?
: string
; disabled?
: string
;
form?
: string
; inputmode?
: string
; maxlength?
: string
;
minlength?
: string
; name?
: string
; placeholder?
: string
;
readonly?
: string
; required?
: string
; rows?
: string
;
spellcheck?
: string
; wrap?
: string
} ; tfoot
:
HTMLElementTagGlobalAttributes
& { align?
: string
} ; th
:
HTMLElementTagGlobalAttributes
& { abbr?
: string
; align?
: string
; axis?
: string
; bgcolor?
:
string
; colspan?
: string
; headers?
: string
; rowspan?
: string
;
scope?
: string
; sorted?
: string
} ; thead
:
HTMLElementTagGlobalAttributes
& { align?
: string
} ; time
:
HTMLElementTagGlobalAttributes
& { datetime?
: string
} ; title
:
HTMLElementTagGlobalAttributes
; tr
:
HTMLElementTagGlobalAttributes
& { align?
: string
} ; track
:
HTMLElementTagGlobalAttributes
& { default?
: string
; kind?
: string
; label?
: string
; src?
:
string
; srclang?
: string
} ; u
:
HTMLElementTagGlobalAttributes
; ul
:
HTMLElementTagGlobalAttributes
& { compact?
: string
} ; var
:
HTMLElementTagGlobalAttributes
; video
:
HTMLElementTagGlobalAttributes
& { autoplay?
: string
; controls?
: string
; crossorigin?
: string
;
height?
: string
; loop?
: string
; mediagroup?
: string
; muted?
:
string
; poster?
: string
; preload?
: string
; src?
: string
;
width?
: string
} ; wbr
:
HTMLElementTagGlobalAttributes
}
Map of HTML element tag attributes.
Remarks
If you need the type of the HTML attributes of an HTML element, this is it.
Example
const getAttribute = <Tag extends keyof HTMLElementTagAttributeMap>(tag: Tag) => (attribute: keyof HTMLElementTagAttributeMap[Tag]) => // ...
See
HTMLElementTagGlobalAttributes
Ζ¬ HTMLElementTagGlobalAttributes:
ReadOnlyRecord
<string
, string
> & {
accesskey?
: string
; aria-activedescendant?
: string
; aria-atomic?
:
string
; aria-autocomplete?
: string
; aria-busy?
: string
;
aria-checked?
: string
; aria-colcount?
: string
; aria-colindex?
:
string
; aria-colspan?
: string
; aria-controls?
: string
;
aria-current?
: string
; aria-describedby?
: string
; aria-details?
:
string
; aria-disabled?
: string
; aria-dropeffect?
: string
;
aria-errormessage?
: string
; aria-expanded?
: string
; aria-flowto?
:
string
; aria-grabbed?
: string
; aria-haspopup?
: string
;
aria-hidden?
: string
; aria-invalid?
: string
; aria-keyshortcuts?
:
string
; aria-label?
: string
; aria-labelledby?
: string
;
aria-level?
: string
; aria-live?
: string
; aria-modal?
: string
;
aria-multiline?
: string
; aria-multiselectable?
: string
;
aria-orientation?
: string
; aria-owns?
: string
; aria-placeholder?
:
string
; aria-posinset?
: string
; aria-pressed?
: string
;
aria-readonly?
: string
; aria-relevant?
: string
; aria-required?
:
string
; aria-roledescription?
: string
; aria-rowcount?
: string
;
aria-rowindex?
: string
; aria-rowspan?
: string
; aria-selected?
:
string
; aria-setsize?
: string
; aria-sort?
: string
;
aria-valuemax?
: string
; aria-valuemin?
: string
; aria-valuenow?
:
string
; aria-valuetext?
: string
; autocapitalize?
: string
; class?
:
string
; contenteditable?
: string
; contextmenu?
: string
; dir?
:
string
; draggable?
: string
; dropzone?
: string
; exportparts?
:
string
; hidden?
: string
; id?
: string
; inputmode?
: string
;
is?
: string
; itemid?
: string
; itemprop?
: string
; itemref?
:
string
; itemscope?
: string
; itemtype?
: string
; lang?
: string
;
onabort?
: string
; onblur?
: string
; oncanplay?
: string
;
oncanplaythrough?
: string
; onchange?
: string
; onclick?
: string
;
oncontextmenu?
: string
; ondblclick?
: string
; ondrag?
: string
;
ondragend?
: string
; ondragenter?
: string
; ondragleave?
: string
;
ondragover?
: string
; ondragstart?
: string
; ondrop?
: string
;
ondurationchange?
: string
; onemptied?
: string
; onended?
: string
;
onerror?
: string
; onfocus?
: string
; onformchange?
: string
;
onforminput?
: string
; oninput?
: string
; oninvalid?
: string
;
onkeydown?
: string
; onkeypress?
: string
; onkeyup?
: string
;
onload?
: string
; onloadeddata?
: string
; onloadedmetadata?
: string
; onloadstart?
: string
; onmousedown?
: string
; onmouseenter?
:
string
; onmouseleave?
: string
; onmousemove?
: string
; onmouseout?
:
string
; onmouseover?
: string
; onmouseup?
: string
; onmousewheel?
:
string
; onpause?
: string
; onplay?
: string
; onplaying?
: string
;
onpointercancel?
: string
; onpointerdown?
: string
; onpointerenter?
:
string
; onpointerleave?
: string
; onpointerlockchange?
: string
;
onpointerlockerror?
: string
; onpointermove?
: string
; onpointerout?
:
string
; onpointerover?
: string
; onpointerup?
: string
;
onprogress?
: string
; onratechange?
: string
; onreadystatechange?
:
string
; onreset?
: string
; onresize?
: string
; onscroll?
: string
; onseeked?
: string
; onseeking?
: string
; onselect?
: string
;
onshow?
: string
; onstalled?
: string
; onsubmit?
: string
;
onsuspend?
: string
; ontimeupdate?
: string
; onvolumechange?
: string
; onwaiting?
: string
; part?
: string
; role?
: string
; slot?
:
string
; spellcheck?
: string
; style?
: string
; tabindex?
: string
; title?
: string
; translate?
: string
}
Global HTML attributes.
Remarks
If you need the type of all HTML attributes, this is it.
Example
const getAttribute = (attribute: keyof HTMLElementTagGlobalAttributes) => // ...
See
Iterables
IsomorphicIterable
Ζ¬ IsomorphicIterable<Item
>:
ReadOnly
<AsyncIterable
<Item
> |
Iterable
<Item
>>
Value might be an AsyncIterable
or just an Iterable
.
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
const iterable: IsomorphicIterable<number> = [1, 2, 3];
for (const item of iterable) { console.log(item); // Works}
for await (const item of iterable) { console.log(item); // Also works}
See
Type parameters
Name | Type | Description |
---|---|---|
Item | unknown | Type of the items in the iterable. |
IsomorphicIterableItem
Ζ¬ 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
const iterable: IsomorphicIterable<number> = [1, 2, 3];const item: IsomorphicIterableItem<typeof iterable> = 1;
See
Type parameters
Name | Type | Description |
---|---|---|
SourceIterable | extends IsomorphicIterable | IsomorphicIterable type to get the item type from.` |
Number
Digit
Ζ¬ 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
const numbers: Iterable<Digit> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
See
Enumerate
Ζ¬ 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
type From0To10 = Enumerate<10>;
Type parameters
Name | Type | Description |
---|---|---|
To | extends number | Last number of the union (starts at 0). |
Accumulator | extends number [] = [] | Accumulator for the recursion (for internal use). |
Numeric
Ζ¬ 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
const numericNumber: Numeric = 42;const numericBigInt: Numeric = 42n;
Radix
Ζ¬ 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
const binary: Radix = 2;const decimal: Radix = 10;const hexadecimal: Radix = 16;
See
Range
Ζ¬ 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
type From5To10 = Range<5, 10>; // 5, 6, 7, 8, 9, 10
See
Type parameters
Name | Type |
---|---|
From | extends number |
To | extends number |
Object
Empty
Ζ¬ Empty: EmptyArray
|
EmptyRecord
|
EmptyString
Empty array, object or string.
Remarks
Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.
Example
const emptyString: Empty = "";const emptyArray: Empty = [];const emptyRecord: Empty = {};
See
EmptyRecord
Ζ¬ EmptyRecord:
ReadOnlyRecord
<PropertyKey
, never
>
Empty record (object).
Remarks
This is a type alias for an empty readonly record. Accessing properties gives
undefined
.
Example
const emptyRecord: EmptyRecord = {};
See
Entry
Ζ¬ Entry<Key
, Value
>: readonly [key: Key, value: 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
const entry: Entry<string, number> = ["π’", 1];
Type parameters
Name | Type | Description |
---|---|---|
Key | PropertyKey | Objectβs properties type. |
Value | unknown | Objectβs values type. |
EntryKey
Ζ¬ EntryKey<Input
>: First
<Input
>
Key of an Entry.
Remarks
Util type to get the key of an Entry.
Example
const entry: Entry<string, number> = ["π’", 1];const entryKey: EntryKey<typeof entry> = entry[0];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends Entry | Entry type. |
EntryOf
Ζ¬ EntryOf<Input
>:
Entry
<KeyOf
<Input
>,
ValueOf
<Input
>>
Object or array Entry.
Remarks
Get the Entry type out of an object or array.
Example
const object = { "π’": 1, "π©": 2,};const entries: EntryOf<typeof object> = Object.entries(object)[0];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | Array or record type. |
EntryValue
Ζ¬ EntryValue<Input
>: Second
<Input
>
Value of an Entry.
Remarks
Util type to get the value of an Entry.
Example
const entry: Entry<string, number> = ["π’", 1];const entryValue: EntryValue<typeof entry> = entry[1];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends Entry | Entry type. |
KeyOf
Ζ¬ KeyOf<Input
>: Input
extends
ArrayLike
?
NeverFallback
<Defined
<Exclude
<Partial
<Input
>["length"
],
Input
["length"
]>>, number
> : `${Exclude<keyof Input, symbol>}`
Generic key for either object or array.
Remarks
Type to represent the type of the key in an
ReadOnlyCollection. It automatically
omits symbol
keys from objects, and uses number
for arrays with dynamic
length
.
Example
const array = [1, 2, 3] as const;const object = { "π’": "π©" } as const;
const arrayKey: KeyOf<typeof array> = 0;const objectKey: KeyOf<typeof object> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | The input ReadOnlyCollection . |
NotEmpty
Ζ¬ 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
const notEmptyString: NotEmpty<string> = "π’";const notEmptyArray: NotEmpty<ReadOnlyArray> = ["π’", "π©"];const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "π’": "π©" };
See
Type parameters
Name | Type | Description |
---|---|---|
Type | extends ArrayLike | object | string | The type to check. |
ReadOnly
Ζ¬ ReadOnly<Input
>: Input
extends Readonly
<ReadonlyMap
<infer Key,
infer Value>> ?
Readonly
<ReadonlyMap
<ReadOnly
<Key
>,
ReadOnly
<Value
>>> : Input
extends
Readonly
<ReadonlySet
<infer Item>> ?
Readonly
<ReadonlySet
<ReadOnly
<Item
>>>
: Input
extends readonly [] ? readonly [] : Input
extends readonly [infer
Head, β¦(infer Tail)] ? readonly
[ReadOnly
<Head
>, β¦ReadOnly<Tail>] :
Input
extends ReadonlyArray
<infer Item> ?
ReadonlyArray
<ReadOnly
<Item
>> : Input
extends Function
? Input
: Input
extends object
? { readonly [Property
in keyof Input]: ReadOnly<Input[Property]> } : Input
Read-only deep any Input
.
Remarks
This type makes any Input
read-only recursively, including nested objects and
arrays, Sets, Maps, and functions.
Example
const record: ReadOnly<Record<string, Array<number>>> = { "π’": [1, 2, 3], "π©": [4, 5, 6],};record["π’"][0] = 7; // Error
Type parameters
Name | Description |
---|---|
Input | The type to make read-only. |
ReadOnlyCollection
Ζ¬ ReadOnlyCollection<Item
>:
ArrayLike
<Item
> |
ReadOnlyRecord
<PropertyKey
, Item
>
Read-only collection (ArrayLike or ReadOnlyRecord).
Remarks
Read-only type union of ArrayLike or ReadOnlyRecord.
Example
const record: ReadOnly<Record<string, Array<number>>> = { "π’": [1, 2, 3], "π©": [4, 5, 6],};record["π’"][0] = 7; // Error
See
Type parameters
Name | Type | Description |
---|---|---|
Item | unknown | Type of the items in the collection. |
ReadOnlyRecord
Ζ¬ 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
,
plus it recursively makes all the values in the record read-only.
Example
const record: ReadOnlyRecord<string, Array<number>> = { "π’": [1, 2, 3], "π©": [4, 5, 6],};record["π’"][0] = 7; // Error
See
Type parameters
Name | Type | Description |
---|---|---|
Key | extends PropertyKey = PropertyKey | Type of the keys in the record. |
Value | unknown | Type of the values in the record. |
ValueOf
Ζ¬ ValueOf<Input
>: Input
[KeyOf
<Input
>
& keyof Input
]
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
const object = { "π’": 1, "π©": 2,};const key: ValueOf<typeof object> = 1;
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ReadOnlyCollection | Type of the collection. |
RegExp
RegularExpression
Ζ¬ 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
const regex: RegularExpression = "/^[a-z]+$/u";
See
RegularExpressionFlags
Ζ¬ RegularExpressionFlags: `${EmptyString | βgβ}${EmptyString | βiβ}${EmptyString | βmβ}${EmptyString | β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
const flags1: RegularExpressionFlags = "u";const flags2: RegularExpressionFlags = "gu";const flags3: RegularExpressionFlags = "iu";const flags4: RegularExpressionFlags = "giu";
See
String
Empty
Ζ¬ Empty: EmptyArray
|
EmptyRecord
|
EmptyString
Empty array, object or string.
Remarks
Union type of EmptyArray, EmptyRecord and EmptyString, to signify values that are empty.
Example
const emptyString: Empty = "";const emptyArray: Empty = [];const emptyRecord: Empty = {};
See
EmptyString
Ζ¬ EmptyString: ""
Empty string.
Remarks
This type is a string with no characters on it (length 0
).
EmptyString.
Example
const emptyString: EmptyString = "";
First
Ζ¬ First<Input
>: Input
[0
]
First value of an ArrayLike.
Remarks
Type of the first item of an ArrayLike
, mainly here to avoid magic numbers.
Example
const array = ["π’", "π©", "π"];const first: First<typeof array> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
Head
Ζ¬ Head<Input
>:
First
<HeadAndTail
<Input
>>
Initial value of an ArrayLike
.
Remarks
Given a type argument (an ArrayLike
), this returns the type of the item in
index 0
.
Example
const array = ["π’", "π©", "π"];const head: Head<typeof array> = "π’";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | ArrayLike value (such as Array or string ). |
HeadAndTail
Ζ¬ HeadAndTail<Input
>: Input
extends readonly [head: infer HeadItem,
tail: infer TailItems] ? readonly [head: HeadItem, tail: TailItems] : Input
extends `${infer FirstCharacter}${infer RestOfString}` ? readonly [head:
FirstCharacter, tail: RestOfString] : Input
extends
EmptyArray
|
EmptyString
? readonly [head: undefined,
tail: Input] : readonly [head: Maybe<Input[number]>, tail: 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
const array = ["π’", "π©", "π"];const headAndTail: HeadAndTail<typeof array> = ["π’", ["π©", "π"]];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Input ArrayLike . |
Initial
Ζ¬ Initial<Input
>:
First
<InitialAndLast
<Input
>>
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
const array = ["π’", "π©", "π"];const initial: Initial<typeof array> = ["π’", "π©"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | ArrayLike value (such as Array or string ). |
InitialAndLast
Ζ¬ InitialAndLast<Input
>: Input
extends readonly [β¦(infer
InitialItems), infer LastItem] ? readonly [initial: InitialItems, last:
LastItem] : Input
extends EmptyArray
|
EmptyString
? readonly [initial: Input,
last: undefined] : Input
extends `${infer FirstCharacter}${infer
RestOfString}` ? readonly [initial: `${RestOfString extends EmptyString ?
EmptyString : FirstCharacter}${Head<InitialAndLast<RestOfString>>}`, last:
`${RestOfString extends EmptyString ? FirstCharacter :
Last<RestOfString>}`] : readonly [initial: Input, last:
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
const array = ["π’", "π©", "π"];const initialAndLast: InitialAndLast<typeof array> = [["π’", "π©"], "π"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Input ArrayLike . |
Last
Ζ¬ Last<Input
>:
Second
<InitialAndLast
<Input
>>
Last value of an ArrayLike
.
Remarks
Type of the last character of a string or the last element of an array.
Example
const array = ["π’", "π©", "π"];const last: Last<typeof array> = "π";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
NotEmpty
Ζ¬ 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
const notEmptyString: NotEmpty<string> = "π’";const notEmptyArray: NotEmpty<ReadOnlyArray> = ["π’", "π©"];const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "π’": "π©" };
See
Type parameters
Name | Type | Description |
---|---|---|
Type | extends ArrayLike | object | string | The type to check. |
Second
Ζ¬ Second<Input
>: Input
[1
]
Second value of an ArrayLike.
Remarks
Type of the Second item of an ArrayLike
, manly here to avoid magic numbers.
Example
const array = ["π’", "π©", "π"];const second: Second<typeof array> = "π©";
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | The input ArrayLike . |
Tagger
Ζ¬ Tagger<Output
, Expressions
>:
Function
<readonly [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
const intParser: Tagger<number> = strings => parseInt(strings.join(""), 10);intParser`100`; // 100
See
Type parameters
Name | Type | Description |
---|---|---|
Output | string | Type of the output value. |
Expressions | extends ReadOnlyArray = ReadOnlyArray | Type of the expressions. |
Tail
Ζ¬ Tail<Input
>:
Second
<HeadAndTail
<Input
>>
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
const array = ["π’", "π©", "π"];const tail: Tail<typeof array> = ["π©", "π"];
See
Type parameters
Name | Type | Description |
---|---|---|
Input | extends ArrayLike | Type of the array to get the tail. |