Skip to content

Latest commit

 

History

History
105 lines (64 loc) · 2.54 KB

File metadata and controls

105 lines (64 loc) · 2.54 KB

my-awesome-typescript-project


my-awesome-typescript-project / src/composed-types

src/composed-types

Composed types.

Table of contents

1. Union types

ecmaPrimitives

type ecmaPrimitives = ecmaPrimitives;

Defined in: src/composed-types.ts:23

Union of primitive types

Remarks

  • Union of all ECMA primitive types.
  • Typescript provides the following types :
    1. any
    2. unknown
    3. never
    4. void
  • Typescript-only types cannot be tested at execution time.

ecmaSpecialCases

type ecmaSpecialCases = ecmaSpecialCases;

Defined in: src/composed-types.ts:34

Union of special types

Remarks

  • Union of all ECMA type-like special cases.
  • null, function and object are not primitive types (see below).
  • null is null and function are special objects that are callable.

2. Intersection types

impossible

type impossible = never;

Defined in: src/composed-types.ts:43

Empty intersection type

Remarks

  • Evaluates to never since the consituents do not overlap.

unit

type unit = "unit";

Defined in: src/composed-types.ts:54

Subtype from a union type

Remarks

  • The unions overlap evaluate to a single value of type string.
  • Thus, this intersection type evaluates to a unit type.
  • Parentheses can be used to constrain operator precedence.

3. Discriminated unions

event

type event = serverEvent | userEvent;

Defined in: src/composed-types.ts:68

Discriminated union types

Remarks

  • Every constituent of a discriminated union type must have a common property set to a literal value.