51 cards
TypeScript is a statically typed superset of JavaScript developed by Microsoft. Because it builds on top of JavaScript, every valid JavaScript file is also a valid TypeScript file, but TypeScript adds optional static typing, interfaces, classes, and modules to improve scalability, maintainability, and developer product...
TypeScript's type system starts with a small set of primitive types: number, string, boolean, null, undefined, symbol, and bigint. These primitives serve as the building blocks for typing variables, function parameters, and return values. To annotate a variable's type explicitly, you place a colon and the type after th...
TypeScript supports multiple ways to express collections of values. Arrays can be written using either bracket syntax, such as let numbers: number[] = [1, 2, 3];, or the generic Array<number> notation. Both forms accept a single uniform type, but heterogeneous data is better expressed with tuples, which are fixed...
Interfaces describe the shape of objects by declaring the names and types of their members. A simple interface Person { name: string; age: number; } tells the compiler that any value typed as Person must have those two properties with those exact types. Because interfaces exist only at compile time, they impose type-ch...
Classes in TypeScript follow standard JavaScript class syntax with the addition of type annotations. A class such as class Animal { name: string; constructor(name: string) { this.name = name; } } declares a property and a constructor in familiar ways. The big difference comes with access modifiers: public members are a...
Generics let you write functions, interfaces, and classes that operate on multiple types while preserving full type safety. A generic identity function written as function identity<T>(arg: T): T { return arg; } takes a value of any type and returns a value of exactly the same type, with TypeScript filling in T fr...
TypeScript supports ES module syntax: import { ModuleName } from './module'; pulls in named exports, import * as Module from './module'; imports a whole namespace, and exports are declared with export function func() {} for named exports or export default class {} for the default export. Re-exporting from another modul...
Strict mode, enabled by setting "strict": true in tsconfig.json, turns on a collection of more rigorous type-checking options, including strictNullChecks and several others. Activated in a new project, strict mode catches a far wider range of potential bugs at compile time and is widely recommended as the default for n...