iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

TS Keywords

TypeScript inherits every JavaScript keyword and adds about a dozen of its own — type-related modifiers and the type-system constructs.

JavaScript keywords TS inherits

const, let, var, function, return, if, else, switch, case, for, while, do, break, continue, class, extends, super, this, new, typeof, instanceof, in, of, void, delete, throw, try, catch, finally, async, await, yield, import, export, default, from, as, true, false, null, undefined.

TypeScript-only keywords

KeywordWhat it does
typeDeclare a type alias.
interfaceDeclare an interface.
enumDeclare an enum.
namespaceDeclare a namespace (legacy).
moduleSame as namespace, older spelling.
declareAmbient declaration (no implementation).
abstractAbstract class / member.
public / protected / privateAccess modifiers.
readonlySet-once property.
overrideExplicit method override.
staticStatic member.
implementsImplement an interface.
keyofUnion of an object's keys.
typeof (type-level)Type of a value.
inferCapture a type in a conditional.
isType predicate return.
assertsAssertion function return.
satisfiesCheck without widening.
as (in expr)Type assertion.
any, unknown, never, void, objectSpecial types.
boolean, number, string, symbol, bigintPrimitive type names.

Soft keywords

Some words are only reserved in specific contexts — you can still name variables type or keyof, but please don't.

Look it up at runtime

TS
// In a TypeScript source file, the compiler resolves these without import.
// At runtime, only the JS subset survives — the rest are erased.
Tip: Don't fight conventions. type, interface, readonly, abstract all have idiomatic uses. Memorise the table once and TS code reads like prose.

Example

Example
// Common reserved words:
// const, let, var, function, return, if, else, switch, case,
// for, while, do, break, continue, class, extends, super, this,
// new, typeof, instanceof, in, of, void, delete, throw, try, catch,
// finally, async, await, yield, import, export, default, from, as,
// type, interface, enum, namespace, module, declare, readonly,
// public, private, protected, abstract, static, override, satisfies
console.log('Plus all JS keywords — TS is a JS superset');
Try it Yourself »

Exercise

TS-only keyword for type aliases.

User = { id: number };

Test yourself

Q1. TypeScript-only keyword for type aliases is…
Q2. TS keyword for "implements an interface" is…
Q3. A keyword that takes a value and gives a type is…

Discussion

Loading…