Options
All
  • Public
  • Public/Protected
  • All
Menu

Module typings/standard-types

Index

Type aliases

DomElement

DomElement: Element | Node | Document | HTMLElement

DomElement

desc

Type representing [DomElement]

Falsy

Falsy: false | "" | 0 | "off"

Falsy

desc

Type representing falsy values in TypeScript: false | "" | 0

example

type Various = 'a' | 'b' | undefined | false;

// Expect: "a" | "b" Exclude<Various, Falsy>;

NonNull

NonNull<T>: NonNullable<T>

NonNull

desc

Excludes null and undefined from T

see

https://flow.org/en/docs/types/utilities/#toc-nonmaybe

example

type StringOrNull = string | null;

// Expect: string type Name = NonNull;

Type parameters

  • T

NullOrNotEmpty

NullOrNotEmpty: Optional<PropertyKey>

NullOrNotEmpty

desc

Type representing null or not empty property key

Nullish

Nullish: null | undefined

Nullish

desc

Type representing [nullish values][https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing] in TypeScript: null | undefined

example

type Various = 'a' | 'b' | undefined;

// Expect: "a" | "b" Exclude<Various, Nullish>;

NumberSet

NumberSet: Set<number | bigint>

NumberSet

desc

Type representing number {@link Set}

ObjectMap

ObjectMap<T>: {}

ObjectMap

desc

Type representing object key-value mappings

Type parameters

  • T

Type declaration

Optional

Optional<T>: T | Nullish

Optional

desc

Type representing [Optional] in TypeScript: T | null | undefined

Type parameters

  • T

OptionalBoolean

OptionalBoolean: Optional<boolean>

OptionalBoolean

desc

Type representing [Optional] boolean type in TypeScript: boolean | null | undefined

OptionalDate

OptionalDate: Optional<Date>

OptionalDate

desc

Type representing [Optional] date type in TypeScript: date | null | undefined

OptionalDomElement

OptionalDomElement: Optional<DomElement>

OptionalDomElement

desc

Type representing optional [DomElement]

OptionalFalsy

OptionalFalsy: Optional<Falsy>

Falsy

desc

Type representing optional falsy values in TypeScript: false | "" | 0 | null | undefined

example

type Various = 'a' | 'b' | undefined | false;

// Expect: "a" | "b" Exclude<Various, OptionalFalsy>;

OptionalNumber

OptionalNumber: Optional<number | bigint>

OptionalNumber

desc

Type representing [Optional] number type in TypeScript: number | bigint | null | undefined

OptionalPropertyKey

OptionalPropertyKey: Optional<PropertyKey>

OptionalPropertyKey

desc

Type representing [Optional] property key type in TypeScript: PropertyKey | null | undefined

OptionalSet

OptionalSet<T>: Set<Optional<T>>

OptionalSet

desc

Type representing optional {@link Set}

Type parameters

  • T

OptionalString

OptionalString: Optional<string>

OptionalString

desc

Type representing [Optional] string type in TypeScript: string | null | undefined

OptionalTruthy

OptionalTruthy: Optional<Truthy>

Truthy

desc

Type representing optional truthy values in TypeScript: true | 1 | 'on' | null | undefined

example

type Various = 'a' | 'b' | undefined | true;

// Expect: "a" | "b" Exclude<Various, OptionalTruthy>;

Primitive

Primitive: Optional<string | number | bigint | boolean | symbol>

Primitive

desc

Type representing Primitive types in TypeScript: string | number | bigint | boolean | symbol | null | undefined

example

type Various = number | string | object;

// Expect: object type Cleaned = Exclude<Various, Primitive>

PropertyKeyRecord

PropertyKeyRecord<T>: Record<PropertyKey, T>

PropertyKeyRecord

desc

Type representing property key {@link Record}

Type parameters

  • T

PropertyKeySet

PropertyKeySet: Set<PropertyKey>

PropertyKeySet

desc

Type representing property key {@link Set}

StringRecord

StringRecord<T>: Record<string, T>

StringRecord

desc

Type representing string {@link Record}

Type parameters

  • T

StringSet

StringSet: Set<string>

StringSet

desc

Type representing string {@link Set}

Truthy

Truthy: true | 1 | "on"

Truthy

desc

Type representing truthy values in TypeScript: true | 1 | 'on'

example

type Various = 'a' | 'b' | undefined | true;

// Expect: "a" | "b" Exclude<Various, Truthy>;

Functions

Const isFalsy

  • isFalsy(value: unknown): value is Falsy
  • Tests for Falsy by simply applying negation ! to the tested val.

    The value is mostly in added type-information and explicitly, but in case of this simple type much the same can often be archived by just using negation !:

    example

    const consumer = (value: boolean | Falsy) => { if (!value) { return ; } type newType = typeof value; // === true // do stuff };

    Parameters

    • value: unknown

    Returns value is Falsy

Const isNullish

  • isNullish(value: unknown): value is undefined | null
  • Tests for Nullish by simply comparing val for equality with null.

    example

    const consumer = (param: Nullish | string): string => { if (isNullish(param)) { // typeof param === Nullish return String(param) + ' was Nullish'; } // typeof param === string return param.toString(); };

    Parameters

    • value: unknown

    Returns value is undefined | null

Const isPrimitive

  • isPrimitive(value: any): value is Optional<string | number | bigint | boolean | symbol>
  • Tests for one of the Primitive types using the JavaScript typeof operator

    Clarification: TypeScript overloads this operator to produce TypeScript types if used in context of types.

    example

    const consumer = (value: Primitive | Primitive[]) => { if (isPrimitive(value)) { return console.log('Primitive value: ', value); } // type of value now inferred as Primitive[] value.map((primitive) => consumer(primitive)); };

    Parameters

    • value: any

      The value to be tested

    Returns value is Optional<string | number | bigint | boolean | symbol>

    If val is primitive. If used in the flow of the program typescript will infer type-information from this.

Const isTruthy

  • isTruthy(value: unknown): value is Truthy
  • Tests for Truthy value

    The value is mostly in added type-information and explicitly but in case of this simple type much the same can often be archived by just using double negation !!:

    example

    const consumer = (value: boolean | Truthy) => { if (!!value) { return ; } type newType = typeof value; // === true // do stuff };

    Parameters

    • value: unknown

    Returns value is Truthy