TypeScript Reference for JS developers

Dmitry Yakimov
BeadList
Published in
2 min readAug 28, 2022

Glossary of keywords, operators, statements and directives

See up to date version on GitHub: https://github.com/welldan97/typescript-reference

Statements

declare, namespace

Built-in Type Primitives

boolean, string, number, undefined, null

bigint, symbol, unique symbol

any, unknown, never, void

Complex Types

|

Array[], Tuple[]

type, interface

enum

Type and Interface Properties

{

property?: Type

readonly property: Type

(...args): Type

new(s: Type)

[key: Type]: Type;

}

Functions

Arguments

{ (this: Type): Type }

{ (...args: Type[]): Type }

Type Guards and Assertion Functions

is, asserts condition, asserts value is Type

Overloads

overloads

Type Manipulation

Basic

!

as

as const

Type[key]

typeof

keyof

extends Type ? IfTrue : IfFalse

infer

Extension

&, extends, merging

Mapped Types

{

[Property in keyof Type]: Type;

-readonly [Property in keyof Type]: Type[Property];

readonly [Property in keyof Type]: Type[Property];

[Property in keyof Type]-?: Type[Property];

[Property in keyof Type]?: Type[Property];

[Properties in keyof Type as NewKeyType]: Type[Properties]

}

Generics

interface NewType<Type>

type NewType<Type>

{ <Type>(arg: Type): Type }

class Class<Type>

Constrains

<Type extends OtherType>

Classes

Properties

{

property?: Type

property!: Type

readonly property: Type

[key: Type]: Type

private property: Type

protected property: Type

declare property: Type

}

Properties present in JS

{

#property: Type

get property(): Type

set property(...args): Type

static property: Type

static {...}

}

Constructor Parameter Properties

{

constructor(parameter arg: Type)

}

Extension

implements

extends

abstract

Decorators

@decorator class Class {

@decorator() property

@decorator method(...args) {...}

method(@decorator arg: Type) {...}

@decorator get accessor() {...}

@decorator set accessor(value) {...}

}

Utility Types

Partial<Type>

Required<Type>

Readonly<Type>

Record<Keys, Type>

Pick<Type, Keys>

Omit<Type, Keys>

Exclude<UnionType, ExcludedMembers>

Extract<Type, Union>

NonNullable<Type>

Parameters<Type>

ConstructorParameters<Type>

ReturnType<Type>

InstanceType<Type>

ThisParameterType<Type>

OmitThisParameter<Type>

ThisType<Type>

Uppercase<StringType>

Lowercase<StringType>

Capitalize<StringType>

Uncapitalize<StringType>

Comment Directives

Enabling and Disabling Typescript

// @ts-ignore

// @ts-check

// @ts-nocheck

// @ts-expect-error

References

/// <reference path="..." />

/// <reference types="..." />

/// <reference lib="..." />

/// <reference no-default-lib="true"/>

/// <amd-module />

/// <amd-dependency />

--

--

Dmitry Yakimov
BeadList

Web-consultant, Tech-enthusiast. Working on BeadList App: beadlist.com