Skip to content

TypeScript Basics

Glossary

94 terms from TypeScript Basics, in plain words, each with the chapter that teaches it.

#

@ts-expect-error / @ts-ignore
Comments that hide the error on the next line. `@ts-expect-error` complains if there is no error to hide, while `@ts-ignore` stays silent.
@types package
A package of type descriptions for code written in JavaScript. `@types/node` describes Node's own modules such as `node:fs` and `process`.

A

any
A special type that turns type checking off for a value, so you can use it in any way and `tsc` never complains. `JSON.parse` returns it, so a typo like `order.qyt` goes unnoticed.
argument
A value you pass to a function when you call it, such as `1650` in `lineTotal(1650, 3)`.
array type (T[])
A type written as the element type followed by `[]`, such as `number[]` for an array of numbers. `Array<Product>` means the same as `Product[]`.
as (type assertion)
Writing `value as Type` tells TypeScript to treat the value as that type, with no check at run time. If you're wrong, as with `JSON.parse(text) as OrderItem` on JSON that says `quantity`, the bug slips through.
as const
Written after a value, it marks the value as never changing: properties become `readonly` and keep their literal types. `["12 oz", "5 lb"] as const` is a read-only list of two exact strings.
assign
To store a value in a variable or property. "Type 'string' is not assignable to type 'number'" means you tried to put a string where only a number may go.
async function
A function marked `async` always returns a promise, and `await` unwraps it to get the value. In TypeScript, such a function's return type is written `Promise<T>`.

C

callback
A function passed to another function to be called later, like `describe` in `printTable`. Its parameters are usually typed from context.
catch variable (error is unknown)
With `strict`, the `error` in `catch (error)` has type `unknown`, because JavaScript can throw any value. Narrow it with `instanceof Error`, or use `String(error)`, before reading `.message`.
class
A JavaScript blueprint for objects, like `GiftCard`. In TypeScript, each property is declared with a type at the top, and the constructor and methods are annotated like functions.
compiler (tsc)
The program that reads your TypeScript, checks every value against its type, and writes plain JavaScript. You run it with `npx tsc`.
compiler option
A single setting in the `compilerOptions` section of `tsconfig.json`, such as `target`, `outDir` or `strict`.
contextual typing
TypeScript working out a type from where a value is used. In `printTable(2, (n) => ...)`, `n` is a number because `printTable` says its callback takes a number.

D

default parameter
A parameter with a value used when the caller leaves the argument out, like `rate = 0`. TypeScript infers its type from the default value.
destructuring
A JavaScript shorthand that unpacks an object's properties or an array's elements into variables, as in `const [sku, bags] = delivery`. With a tuple, each variable gets its own type.
dev dependency
A package needed only while you develop, not when the program runs. You install TypeScript this way with `npm install -D typescript`.
discriminated union
A union of object types that each have a shared property with a literal type, such as `kind`. Checking that property narrows to one member, as with Kettle & Crane's card, giftCard and invoice payments.
dist
The folder where `tsc` writes the compiled JavaScript, set by `outDir`. You run files from here and never edit them by hand.
DOM (Document Object Model)
The set of objects a browser builds for every element on a page. Your code changes the page by changing these objects.

E

ECMAScript (ES)
The official name of the JavaScript language, with versions named by year. The `target` option such as `es2024` picks which version `tsc` writes.
emit
To write out the JavaScript files. `noEmitOnError` stops that while errors remain, and `--noEmit` checks without writing anything.
enum
A named set of values, such as `Carrier.UPS`. Unlike most TypeScript, it compiles to real JavaScript code, so many teams use unions of string literals instead.
erasableSyntaxOnly
A compiler option that makes `tsc` reject TypeScript features, such as enums, that can't simply be erased to get JavaScript.
event
Something that happens on a web page, such as a click or key press. `addEventListener` asks the browser to call your callback each time it happens.
excess property check
An error when an object written directly where an interface is expected has properties the interface doesn't list. It mostly catches typos.
export / import
JavaScript's way to share code between files: `export` makes something available and `import` brings it in. TypeScript interfaces and types can be exported too.
extends (interfaces)
An interface can extend another, taking all its properties and adding more. `WholesaleProduct extends Product` adds `minBags`.

F

function type
The type of a function, written like an arrow function with types in place of code, such as `(bags: number) => string`. The parameter names are just labels.

G

generics
Types that take another type in angle brackets to fill in a detail, such as `Promise<number>` for a promise that gives a number. They let one type definition work with many different inner types.

H

hoisting
A JavaScript behavior where function declarations are set up before any code runs, so they can be called above their own line. This is why TypeScript can't be sure a null check has run before a `function` declaration is called.
HTMLInputElement
TypeScript's built-in types for page elements: `Element` is the general one, and `HTMLInputElement` is an input box, which has `value` and `valueAsNumber`.

I

implements
A keyword that makes a class promise to match an interface. If the class lacks something the interface lists, `tsc` reports an error.
in operator
A JavaScript operator where `"tracking" in d` is true if object `d` has a property called `tracking`. TypeScript uses it to narrow unions of objects.
index signature
A type like `{ [sku: string]: Product }` that says any string key maps to a value of that type. It types lookup tables such as the product catalog, whose keys aren't known in advance.
instanceof
A JavaScript operator that checks whether a value was made by a certain class. TypeScript uses it to narrow, such as `box instanceof HTMLInputElement` or `error instanceof Error`.
interface
A named description of an object's shape, such as `Product` with `sku`, `name` and `priceCents`. It exists only for `tsc` and produces no JavaScript.

J

JSON.parse
A JavaScript function that turns JSON text into a value. TypeScript types its result as `any`, since it can't know what the text holds.

K

KeyboardEvent
The types of event objects handed to callbacks: a `"keydown"` event is a `KeyboardEvent` with a `key` property, and a `"click"` event is a `PointerEvent`.

L

literal type
A type with exactly one value, such as `"UPS"` or `12`. A union of literals like `"UPS" | "USPS" | "FedEx"` lists the only allowed choices.
LTS (Long-Term Support)
A Node.js release line that receives bug fixes and security updates for an extended period. It is the version most people should install because it is stable and well supported.

M

member (of a union)
Each individual type inside a union. In `number | string`, `number` and `string` are the members.
module (compiler option)
`"module": "nodenext"` makes `tsc` follow Node's rules for `import` and `export`, together with `"type": "module"` in `package.json`.

N

narrowing
Turning a wider type, such as a union, into a narrower one with a check like `typeof id === "number"`. Inside the `if`, TypeScript knows the more specific type.
never
The type with no values. A function that always throws, like `fail`, returns `never`, and a `never` check in a `switch` catches missing cases.
Node.js
A program that runs JavaScript outside a browser. It is used to run compiled JavaScript files, such as the output of the TypeScript compiler in a `dist` folder.
noFallthroughCasesInSwitch
An extra check that reports a `case` that runs on into the next because its `break` is missing.
noImplicitAny
A strict check that makes a missing parameter type an error instead of a silent `any`.
noImplicitReturns
An extra check that reports a function where some paths return a value and others don't.
non-null assertion
A `!` after a value tells TypeScript it isn't `null` or `undefined`, with no check at all. If it's wrong, the program crashes.
noUncheckedIndexedAccess
An extra option that adds `undefined` to every lookup by index or key, such as `prices[0]` or `PRODUCTS[sku]`. It forces a check for a missing SKU.
npm
Node's package manager. `npm init -y` starts a project, `npm install` adds packages, and scripts in `package.json` run with `npm run`.
npx
A command that runs a tool installed in the project, such as `npx tsc`, using the project's own copy.

O

object type
A type listing an object's properties and their types in braces, like `{ sku: string; priceCents: number }`.
optional (property or parameter)
A `?` after a property or parameter name means it may be missing, so reading it might give `undefined`. TypeScript then makes you handle that case.
optional chaining (?.) and nullish coalescing (??)
`?.` gives `undefined` instead of crashing when the left side is `null` or `undefined`, and `??` supplies a default in that case. Both are used to handle missing values.
outside data (checking where it enters)
Data from JSON files or other services arrives while the program runs, so types can't vouch for it. Read it as `unknown` and narrow it into a real type where it enters, as `parseOrder` does.

P

parameter
The name that receives a value inside a function, such as `priceCents` in `lineTotal`. Every parameter should be annotated.
Promise<T>
The type of a value that arrives later. `Promise<number>` is what an `async` function returning a number gives, and `await` unwraps it.

Q

querySelector
A browser function that returns the first page element matching a CSS selector, or `null` if there is none. TypeScript includes `null` in its return type.

R

readonly
A property or array marked `readonly` can't be changed after creation. `readonly string[]` removes methods like `push`.
Record<K, V>
A built-in utility type meaning an object with keys of type `K` and values of type `V`. With `Record<StateCode, number>`, the object needs exactly one entry per state.
rest parameter
A function parameter written with `...` that collects extra arguments into an array, so its type is an array type like `number[]`.
return type
The type a function returns, written after its parameters, like `: number`. TypeScript infers it, but writing it makes a promise that `tsc` enforces.
rootDir
A compiler option naming the folder that holds your TypeScript source, such as `src`.

S

static checking
Finding mistakes without running the code. TypeScript's checks happen at your desk, not at the customer's checkout.
strict
A `tsconfig.json` option that turns on a family of checks, including `noImplicitAny`, `strictNullChecks`, `strictPropertyInitialization` and `useUnknownInCatchVariables`. It is the default in TypeScript 7.
strictNullChecks
A strict check that allows `null` and `undefined` only where the type says so, so a `string` is always a real string.
strictPropertyInitialization
A strict check that every class property must get a value, either where it's declared or in the constructor.
structural typing
TypeScript compares objects by their shape, not by name, so any object with the right properties counts as a `Product` even if never declared as one.
switch
A JavaScript statement that picks a branch by a value. TypeScript narrows the value in each `case` and notices a missing case in a union.

T

target
A compiler option naming the version of JavaScript that `tsc` writes, such as `es2024`.
tsc --noEmit / --watch
`npx tsc --noEmit` checks the whole project without writing JavaScript. `npx tsc --watch` keeps running and checks and compiles again every time you save.
tsconfig.json
The file in the project folder where `tsc` reads its settings, such as `rootDir`, `outDir` and `strict`.
tuple
A fixed-length array with its own type for each position, like `[string, number]` for a SKU and a count.
type
What kind of value something is, and so what you can do with it, such as `number` or `string`.
type alias
A name for any type, made with the keyword `type`, such as `type Cents = number;`. For object shapes it is nearly interchangeable with `interface`.
type annotation
A colon and a type after a name, such as `const bagsSold: number = 42`, saying what the value must hold.
type checking
Checking every use of every value against its type, which `tsc` does before the code runs.
type guard
A check that narrows a type, such as `typeof x === "number"`.
type inference
TypeScript working out a type from the code, such as from the starting value of a variable, so you often don't need to annotate.
type stripping
What newer Node does to run a `.ts` file directly: it deletes the annotations and runs the rest, with no type checking. It can't handle features like enums.
typeof
A JavaScript operator giving a value's type name as text, such as `"number"`. TypeScript narrows unions by it. In a type, `typeof STATES` means the type of the value `STATES`.
TypeScript
JavaScript with type annotations added, checked by `tsc` before the code runs. The types are removed when it is compiled to JavaScript.
TypeScript error code (TS2322)
The `TS` plus number, such as `TS2322`, that ends the first line of a compiler error. Search the web for it to find explanations and examples.
TypeScript Playground
A free web page at typescriptlang.org/play where you can try TypeScript without installing anything and see its errors and the JavaScript it becomes.

U

union type
A type like `number | string` that allows a value of either type. Inside a function you may only do what works for every member, until you narrow it.
unknown
A type for a value that could be anything, where TypeScript lets you do nothing with it until you narrow it. It's the safe alternative to `any` for outside data like parsed JSON.
utility type
A built-in type that builds another type, such as `Record`. *TypeScript Beyond the Basics* covers them.

V

valueAsNumber
A property of a number input box that gives the typed number, or `NaN` if the box is empty. This is better than `value`, which is always a string.
void
The return type of a function that returns nothing, such as one that only prints.
VS Code
A free code editor from Microsoft. It underlines type errors as you type and shows inferred types when you hover over code, and its Live Preview extension serves web pages locally.

W

widening
TypeScript inferring a general type such as `string` instead of `"UPS"` for a value that can change, like a `let` variable or an object property.