programmingintermediate
TypeScript Basics
Learn TypeScript fundamentals including types, interfaces, and generics
6 cardsFlashcardMaker0 clones
Clone this Deck & Start StudyingFlashcards (6)
Card 1
What is TypeScript?
TypeScript is a statically typed superset of JavaScript that compiles to plain JavaScript, adding optional static typing and other features.
Card 2
What is the difference between interface and type in TypeScript?
Interfaces are extendable and primarily for object shapes. Types are more flexible (can define unions, intersections, primitives) but cannot be re-opened to add new properties.
Card 3
What are generics in TypeScript?
Generics allow you to create reusable components that work with multiple types while maintaining type safety. Example: function identity<T>(arg: T): T { return arg; }
Card 4
What is the "any" type and when should you avoid it?
"any" disables type checking for a value. Avoid it when possible as it defeats the purpose of TypeScript. Use "unknown" for safer type-unknown scenarios.
Card 5
What is a union type?
A union type allows a value to be one of several types. Example: let value: string | number can be either a string or number.
Card 6
What is type assertion in TypeScript?