All types and classes will be named T
, U
, V
in that order.
Everything else - e.g. variables, functions, keys and namespaces -
will be named a
, b
, c
or A
, B
, C
, in that order.
All functions take 0 parameters, unless the feature is related to function parameters.
All strings will use single-quotes (''
), except when template strings (` `
) are necessary.
If you still can’t find the syntax construct, try using spaces in different places.
JavaScript constructs are here for completeness, however they will not have their own page in the language reference.
Relevant links to the TypeScript Handbook will be in the form (HB).
Relevant links to the Mozilla Developer Network JavaScript reference will be in the form (MDN).
a: T
- type annotationslet a!: T
, var a!: T
- non-null declarationsa?: T
, a(b?: T)
module A {}
- namespaces
(HB)
(soft deprecated - prefer namespace
) (<v1.0+)namespace A {}
- namespaces
(HB)
(v1.5+, i2159, pr2923)declare namespace A {}
- ambient namespace
(HB)a in b
- in
operator
(HB)
(MDN)a as T
- type assertion, as
operator
(HB)
(v????+, i296, pr3564)<T> a
- type assertion (legacy)<T>()
, <T,>()
, function a<T>
- generic function<div></div>
, <a></a>
, <div />
, <a />
- JSX
([HB])
(MDN)
(v++++?, i3203, pr3564)type T
- typetype T<U>
- generic typeclass T
- classclass T<U>
- generic class<const T>
- const
generic modifier
(@a
- decorator
(v1.5+)#a
- JavaScript private field
(HB)
(MDN)this
- this
type
(HB)this is T
- this
-based type guard
(HB)a is T
- user-defined type guardT extends U ? V : W
- conditional types
(v2.8+)
(HB)
T extends T ? U : never
, T extends U ? V : never
- distributive conditional types
(v2.8+)
(HB)class T extends U
- class/interface extends
clause
(HB)
(MDN)class T implements U
- class implements
clause
(HB)interface T extends U
a satisfies T
- satisfies
operator (v4.9+)// @ts-expect-error
- error suppression
(v3.9+)// @ts-ignore
- diagnostic suppression// @ts-check
- typechecking activation
(HB)// @ts-nocheck
- typechecking suppression
(HB){ [T in keyof U]?: V; }
, { [T in U]?: V; }
, { [T in keyof U]-?: V; }
- optional mapped type modifier
(HB)readonly [T]
- readonly tuple
(v3.4+)readonly T[]
- readonly array
(v3.4+)a as const
- const
assertion
(v3.4+, i10195, i20195, i26979, pr29510)(Yes, they’re technically not syntax, but they’re included here for)
a!
, a!.b
, a![b]
, a!()
- non-null assertions
(HB)a?.b
, a?.[b]
, a?.b()
- optional chaining
(MDN)a ?? b
- nullish coalescing
(MDN)var a
- var
declaration
(soft deprecated - prefer let
or const
. note that there are differences)
(MDN)let a
- let
declaration
(v1.5+)
(MDN)const a
- const
declaration
(v1.5+)
(MDN){ [a]: b }
- computed property name
(v1.5+)
(MDN)for (const a in b)
, for (let a in b)
, for (var a in b)
- for
-in
statement
(MDN)for (const a of b)
, for (let a of b)
, for (var a of b)
- for
-of
statement (v1.5+)
(MDN)for await (const a of b)
, for await (let a of b)
, for await (var a of b)
- for await
-of
statement
(MDN)import a from 'b';
, import * as a from 'b';
, import { a } from 'b';
, import { a as b } from 'c';
- ES6 module (ESM) import
statement
(HB)
(MDN)
(v????, pr1983)export * from 'a';
, export
- ES6 module (ESM) export
statement
(HB)
(MDN)
(v????, pr1983)