TypeScript Flashcards
(48 cards)
What is TypeScript?
TypeScript is a superset of JavaScript that adds static typing.
Static Typing
TypeScript allows you to define variable types, making code more predictable and easier to debug.
Transpilation
TypeScript code is compiled into JavaScript for execution in browsers or Node.js.
TypeScript File Extension
TypeScript files use the .ts extension.
Benefits of TypeScript
Improves code quality, better error detection, supports modern JS features.
Interfaces
Used to define contracts for objects, specifying their structure.
Classes in TypeScript
Allow for creating objects with defined properties and methods, supporting OOP principles.
Enums
Define a set of named constants, making code more readable.
Generics
Enable writing reusable and type-safe code components.
Union Types
Allow variables to hold more than one type, e.g., string | number.
Type Aliases
Provide a way to name and reuse custom types.
Literal Types
Restrict a variable to specific values, e.g., let direction: ‘up’ | ‘down’.
Type Inference
TypeScript can infer variable types based on assigned values.
Any Type
A type that disables type checking, useful in dynamic code.
Never Type
Indicates values that never occur, e.g., in unreachable code.
Void Type
Used for functions that don’t return a value.
Tuple
An array with fixed types and length.
Type Assertion
Tell the compiler to treat a value as a specific type using as or <>.
Optional Parameters
Functions can define optional parameters with the ? syntax.
Readonly Modifier
Prevents reassignment of properties or variables.
Access Modifiers
Keywords like public, private, and protected control property access.
Default Parameters
Functions can have parameters with default values.
Decorators
Special annotations used to modify classes or methods at runtime.
Namespaces
Used to organize and group related code.