Master Typescript Essentials with 51 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
TypeScript is a statically typed superset of JavaScript developed by Microsoft that compiles to plain JavaScript code. It adds optional static typing, interfaces, classes, and modules to enhance code scalability, maintainability, and developer productivity.
TypeScript is a superset of JavaScript, meaning all valid JavaScript code is also valid TypeScript. TypeScript code is transpiled to JavaScript, allowing it to run in any JavaScript environment.
Install TypeScript globally using npm install -g typescript or locally as a dev dependency with npm install typescript --save-dev. Verify installation with tsc --version.
The TypeScript compiler is invoked with tsc. Use tsc file.ts to compile a single file or tsc to compile based on tsconfig.json.
tsconfig.json is the TypeScript configuration file that specifies compiler options like target JavaScript version, module system, and strictness mode. It controls how TypeScript projects are compiled.
Primitive types include number, string, boolean, null, undefined, symbol, and bigint. They are the basic building blocks for typing variables.
Use a type annotation after the variable name with a colon: let name: string = "Alice";. TypeScript infers types when possible but explicit annotations improve clarity.
TypeScript automatically infers the type of a variable from its initializer. For example, let count = 5; infers number, reducing boilerplate while maintaining type safety.
The any type disables type checking, allowing a value to be treated as any type. It should be used sparingly as it bypasses TypeScript's benefits; prefer unknown for safer alternatives.
unknown is a top type like any but safer, requiring type checks or narrowing before use. It ensures type safety by preventing direct operations on unknown values.
The never type represents values that never occur, such as exhaustive switch statements or impossible code paths. It is useful for function return types that always throw errors.
Use array syntax like let numbers: number[] = [1, 2, 3]; or generic Array<number>. Arrays can hold homogeneous or heterogeneous types with tuples.
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge