Skip to main content

types

package @remirror/types

interface Coords

Defines coordinates returned by the [[EditorView.coordsAtPos]] function.

Signature:

export interface Coords 

property bottom

Vertical distance from the top of the page viewport to the bottom side of the described position (px).

Signature:

bottom: number;

property left

Horizontal distance from the left of the page viewport to the left side of the described position (px).

Signature:

left: number;

property right

Horizontal distance from the left of the page viewport to the right side of the described position (px).

Signature:

right: number;

property top

Vertical distance from the top of the page viewport to the top side of the described position (px).

Signature:

top: number;

interface Flavoring

Used by Flavor to mark a type in a readable way.

Signature:

export interface Flavoring<Name> 

property [_flavor]

Signature:

readonly [_flavor]?: Name;

interface ObjectMark

A JSON representation of a prosemirror Mark.

Signature:

export interface ObjectMark 

property attrs

Signature:

attrs?: Record<string, Literal>;

property type

Signature:

type: string;

interface Shape

An object with string keys and values of type any

Signature:

export interface Shape 

Signature:

[key: string]: any;

type And

A shorthand for creating and intersection of two object types.

Signature:

export declare type And<Type extends Shape, Other extends Shape> = Type & Other;

References: Shape

type AnyConstructor

Matches any constructor type.

Signature:

export declare type AnyConstructor<Type = any> = new (...args: any[]) => Type;

type AnyFunction

Concisely and cleanly define an arbitrary function.

Signature:

export declare type AnyFunction<Type = any> = (...args: any[]) => Type;

Remarks:

Taken from simplytyped Useful when designing many api's that don't care what function they take in, they just need to know what it returns.

type Array1

An array which must include the first item.

Signature:

export declare type Array1<Type> = MinArray<Type, 1>;

References: MinArray

type Array2

An array which must include the first 2 items.

Signature:

export declare type Array2<Type> = MinArray<Type, 2>;

References: MinArray

type Array3

An array which must include the first 3 items.

Signature:

export declare type Array3<Type> = MinArray<Type, 3>;

References: MinArray

type Brand

Create a "branded" version of a type. TypeScript won't allow implicit conversion to this type

Signature:

export declare type Brand<Type, B> = Type & Branding<B>;

type ConditionalReturnKeys

Conditionally pick keys which are functions and have the requested return type.

Signature:

export declare type ConditionalReturnKeys<Base, Return> = NonNullable<{
[Key in keyof Base]: Base[Key] extends AnyFunction<infer R> ? R extends Return ? Key : never : never;
}[keyof Base]>;

References: AnyFunction

type ConditionalReturnPick

Pick the properties from an object that are methods with the requested Return type.

Signature:

export declare type ConditionalReturnPick<Base, Return> = Pick<Base, ConditionalReturnKeys<Base, Return>>;

References: ConditionalReturnKeys

type DeepPartial

A recursive partial type. Useful for object that will be merged with defaults.

Signature:

export declare type DeepPartial<Type> = Type extends object ? {
[K in keyof Type]?: DeepPartial<Type[K]>;
} : Type;

References: DeepPartial

type DeepString

Converts every nested type to a string.

Signature:

export declare type DeepString<Type> = Type extends object ? {
[K in keyof Type]: DeepString<Type[K]>;
} : string;

References: DeepString

type Diff

Get the diff between two types. All identical keys are stripped away.

Signature:

export declare type Diff<A, B> = Omit<A, keyof B> & Omit<B, keyof A>;

Remarks:

type Fun = Diff<{notFun: false, fun: true}, {notFun: true, wow: string}>;
// => { fun: true, wow: string }

type EmptyShape

An alternative to usage of {} as a type.

Signature:

export declare type EmptyShape = Record<never, never>;

type Flavor

Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding.

Signature:

export declare type Flavor<Type, Name> = Type & Flavoring<Name>;

References: Flavoring

type FlipPartialAndRequired

Reverses the partial and required keys for the type provided. If it was a required property it becomes a partial property and if it was a partial property it becomes a required property.

Signature:

export declare type FlipPartialAndRequired<Type extends Shape> = PickPartial<Type> & Partial<PickRequired<Type>>;

References: Shape, PickPartial, PickRequired

type GetRequiredKeys

Get all the keys for required properties on this type.

Signature:

export declare type GetRequiredKeys<Type extends Shape> = keyof ConditionalPick<KeepPartialProperties<Type>, NeverBrand>;

References: Shape, KeepPartialProperties

type IfEmpty

Conditional type which checks if the provided Type is and empty object (no properties). If it is uses the Then type if not falls back to the Else type.

Signature:

export declare type IfEmpty<Type extends object, Then, Else> = keyof Type extends never ? Then : Else;

type IfHasRequiredProperties

Checks the type provided and if it has any properties which are required it will return the Then type. When none of the properties are required it will return the Else type.

Signature:

export declare type IfHasRequiredProperties<Type extends object, Then, Else> = IfNoRequiredProperties<Type, Else, Then>;

References: IfNoRequiredProperties

Remarks:

This is a reverse of the IfNoRequiredProperties type.

type IfMatches

Condition that checks if the keys of the two objects match. If so, respond with Then otherwise Else.

Signature:

export declare type IfMatches<A, B, Then, Else> = IfEmpty<Diff<A, B>, Then, Else>;

References: IfEmpty, Diff

type IfNoRequiredProperties

A conditional check on the type. When there are no required keys it outputs the Then type, otherwise it outputs the Else type.

Signature:

export declare type IfNoRequiredProperties<Type extends object, Then, Else> = GetRequiredKeys<Type> extends NeverBrand ? Then : Else;

References: GetRequiredKeys

Remarks:

This is useful for dynamically setting the parameter list of a method call depending on whether keys are required.

type IndexUnionFromTuple

Extract the valid index union from a provided tuple.

import { IndexUnionFromTuple } from '@remirror/core-types';

const tuple = ['a', 'b', 'c'];
type Index = IndexUnionFromTuple<typeof tuple> => 0 | 1 | 2

Signature:

export declare type IndexUnionFromTuple<Tuple extends readonly unknown[]> = Tuple extends Tuple ? number extends Tuple['length'] ? number : _IndexUnionFromTuple<[], Tuple['length']> : never;

type JsonPrimitive

Matches any valid JSON primitive value.

Signature:

export declare type JsonPrimitive = string | number | boolean | null;

type KeepPartialProperties

Keeps the partial properties of a type unchanged. Transforms the rest to never.

Signature:

export declare type KeepPartialProperties<Type extends Shape> = {
[Key in keyof Type]: Type[Key] extends undefined ? Type[Key] : NeverBrand;
};

References: Shape

type Listable

Allow a type of a list of types.

Signature:

export declare type Listable<Type> = Type | Type[];

type Literal

All the literal types

Signature:

export declare type Literal = string | number | boolean | undefined | null | void | object;

type MakeNullable

Makes specified keys of an interface nullable while the rest stay the same.

Signature:

export declare type MakeNullable<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]: Type[Key] | null;
};

type MakeOptional

Makes specified keys of an interface optional while the rest stay the same.

Signature:

export declare type MakeOptional<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]+?: Type[Key];
};

type MakeReadonly

Makes specified keys of an interface readonly.

Signature:

export declare type MakeReadonly<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
+readonly [Key in Keys]: NonNullable<Type[Key]>;
};

type MakeRequired

Makes specified keys of an interface Required while the rest remain unchanged.

Signature:

export declare type MakeRequired<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]-?: Type[Key];
};

type MakeUndefined

Makes specified keys of an interface optional while the rest stay the same.

Signature:

export declare type MakeUndefined<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]: Type[Key] | undefined;
};

type MinArray

Create a type for an array (as a tuple) which has at least the provided Length.

This can be useful when noUncheckedIndexedAccess is set to true in the compiler options. Annotate types when you are sure the provided index will always be available.

import { MinArray } from '@remirror/core-types';

MinArray<string, 2>; // => [string, string, ...string[]];

Signature:

export declare type MinArray<Type, Length extends number> = Length extends Length ? number extends Length ? Type[] : _MinArray<Type, Length, []> : never;

type NonNullableShape

Signature:

export declare type NonNullableShape<Type extends object> = {
[Key in keyof Type]: NonNullable<Type[Key]>;
};

type Nullable

Makes a type nullable or undefined.

Signature:

export declare type Nullable<Type> = Type | null | undefined;

type PartialWithRequiredKeys

Make the whole interface partial except for some specified keys which will be made required.

Signature:

export declare type PartialWithRequiredKeys<Type extends object, Keys extends keyof Type> = Partial<Pick<Type, Exclude<keyof Type, Keys>>> & Required<Pick<Type, Keys>>;

type PickPartial

Pick the partial properties from the provided Type and make them all required.

Signature:

export declare type PickPartial<Type extends Shape> = {
[Key in keyof ConditionalExcept<KeepPartialProperties<Type>, NeverBrand>]-?: Type[Key];
};

References: Shape, KeepPartialProperties

type PickRequired

Only pick the required (non-partial) types from the given Type.

Signature:

export declare type PickRequired<Type extends Shape> = {
[Key in keyof ConditionalPick<KeepPartialProperties<Type>, NeverBrand>]: Type[Key];
};

References: Shape, KeepPartialProperties

type Predicate

Creates a predicate type.

Signature:

export declare type Predicate<Type> = (value: unknown) => value is Type;

type ProsemirrorAttributes

Used for attributes which can be added to prosemirror nodes and marks.

Signature:

export declare type ProsemirrorAttributes<Extra extends object = object> = Record<string, unknown> & Remirror.Attributes & Extra & {
class?: string;
};

type RemoveFlavoring

Remove the flavoring from a type.

Signature:

export declare type RemoveFlavoring<Type, Name> = Type extends Flavor<infer T, Name> ? T : Type;

References: Flavor

type Replace

Replace and extend any object keys.

Signature:

export declare type Replace<Type, Replacements extends Shape> = Omit<Type, keyof Replacements> & Replacements;

References: Shape

type Simplify

When a type is really deep and has retained an unnecessary amount of type information, this flattens it to a single array/object/value.

TODO not using it right now as it's breaking with globally available types via namespace.

Signature:

export declare type Simplify<T> = T extends object | any[] ? {
[K in keyof T]: T[K];
} : T;

type StrictReplace

Replace only the current keys with different types.

Signature:

export declare type StrictReplace<Type, Replacements extends Record<keyof Type, unknown>> = Omit<Type, keyof Replacements> & Replacements;

type StringKey

An alternative to keyof that only extracts the string keys.

Signature:

export declare type StringKey<Type> = Extract<keyof Type, string>;

type TupleOf

Create a tuple of Size from the provided Type.

Signature:

export declare type TupleOf<Type, Size extends number> = Size extends Size ? number extends Size ? Type[] : _TupleOf<Type, Size, []> : never;

type TupleUnion

Returns tuple types that include every string in union TupleUnion<keyof {bar: string; leet: number }>; ["bar", "leet"] | ["leet", "bar"];

Taken from ❤️ https://github.com/microsoft/TypeScript/issues/13298\#issuecomment-692864087

Problem it is recursive and has quickly eats into the maximum depth.

Signature:

export declare type TupleUnion<T> = ((T extends any ? (t: T) => T : never) extends infer U ? (U extends any ? (u: U) => any : never) extends (v: infer V) => any ? V : never : never) extends (_: any) => infer W ? [...TupleUnion<Exclude<T, W>>, W] : [];

References: TupleUnion

type TupleValue

Extract the values of a tuple as a union type.

Signature:

export declare type TupleValue<Tuple extends readonly unknown[]> = Tuple[number];

Remarks:

const myTuple = ['a', 'b', 'c'] as const;

type MyTuple = TupleValue<typeof myTuple>; // 'a' | 'b' | 'c'

type UndefinedFlipPartialAndRequired

Reverses the partial and required keys for the type provided. If it was a required property it becomes a partial property and if it was a partial property it becomes a required property.

Signature:

export declare type UndefinedFlipPartialAndRequired<Type extends Shape> = UndefinedPickPartial<Type> & Partial<PickRequired<Type>>;

References: Shape, UndefinedPickPartial, PickRequired

type UndefinedPickPartial

Like pick partial but all types can still specify undefined.

Signature:

export declare type UndefinedPickPartial<Type extends Shape> = {
[Key in keyof PickPartial<Type>]: PickPartial<Type>[Key] | undefined;
};

References: Shape, PickPartial

type UnknownShape

An object with string keys and values of type unknown

Signature:

export declare type UnknownShape<Type = unknown> = Record<string, Type>;

type UseDefault

When the type is never use a default type instead.

TODO why doesn't this work

Signature:

export declare type UseDefault<Type, Default> = Type extends never ? Default : Type;

type Value

Extract the values of an object as a union type.

Signature:

export declare type Value<Type> = Type[keyof Type];

Remarks:

const myRecord = { A: 'a', B: 'b', C: 'c' } as const;

type MyRecord = Value<typeof myRecord>; // 'a' | 'b' | 'c'

type Writeable

Remove all readonly modifiers from the provided type.

Signature:

export declare type Writeable<Type> = {
-readonly [Key in keyof Type]: Type[Key];
};