TypeScript: Types, Interfaces & Generics
77 cards · 🇺🇸 English
Core TypeScript type system: types, interfaces, and generics.
Study all 77 cards for free
Flashcards, quizzes, pixel-art games and a daily review that remembers for you.
Try the first 10 cards
1 / 10Three primitive types in TypeScript
Tap the card for the answer · swipe right if you knew it, left if not
Already have an account? Sign in
Cards
- 1Three primitive types in TypeScriptstring, number, and boolean
- 2Why should you use lowercase type names (string, number, boolean)?The capitalized versions (String, Number, Boolean) refer to special built-in types that rarely appear in your code
- 3Specify the type of an array in TypeScriptUse number[] or Array<number> syntax (both are equivalent)
- 4'any' type in TypeScriptA special type that disables all type checking - you can access any properties, call it as a function, or assign it to any type
- 5What compiler flag prevents implicit 'any' types?noImplicitAny
- 6Where do type annotations go in TypeScript?After the thing being typed (not before like int x = 0 in other languages)
- 7Type inferenceTypeScript automatically determining types based on context, like inferring a variable's type from its initializer
- 8Add a type annotation to a function parameterAfter the parameter name: function greet(name: string) { ... }
- 9Specify a function's return typeAfter the parameter list: function getFavoriteNumber(): number { ... }
- 10Contextual typingWhen TypeScript infers parameter types based on how and where a function is used (e.g., in array.forEach)
- 11Define an object type inlineList properties and types: function printCoord(pt: { x: number; y: number }) { ... }
- 12Make an object property optionalAdd a ? after the property name: { first: string; last?: string }
- 13What happens when you access an optional property?You get undefined if it doesn't exist, so you must check for undefined before using it
- 14Union typeA type formed from two or more other types, representing values that may be any one of those types
- 15Define a union typeUse the pipe operator: number | string
- 16NarrowingWhen TypeScript deduces a more specific type for a value based on the structure of the code (e.g., after a typeof check)
- 17How can you narrow a union type?Use typeof checks, Array.isArray(), or other runtime checks to determine which type it is
- 18Type aliasA name for any type, defined with: type Point = { x: number; y: number }
- 19Can type aliases be used for union types?Yes: type ID = number | string
- 20Interface in TypeScriptA way to name an object type with its properties and their types
- 21Main difference between interfaces and type aliasesInterfaces can be re-opened to add new properties (declaration merging), type aliases cannot
- 22Extend an interfaceinterface Bear extends Animal { honey: boolean }
- 23Extend a type aliasUse intersection: type Bear = Animal & { honey: boolean }
- 24Can you reopen a type alias to add properties?No, a type cannot be changed after being created
- 25Type assertionA way to tell TypeScript a more specific type than it knows: document.getElementById('canvas') as HTMLCanvasElement
- 26Alternative syntax for type assertionsAngle brackets: <HTMLCanvasElement>document.getElementById('canvas') (not usable in .tsx files)
- 27Do type assertions affect runtime behavior?No, they are removed by the compiler and have no runtime impact
- 28Literal typeA type that refers to a specific string or number value, like 'hello' or 42
- 29How are const variables typed vs let variables?const gets a literal type (const x = 'hello' → type 'hello'), let gets a general type (let x = 'hello' → type string)
- 30How can you use literal types with unions?To restrict values to a specific set: alignment: 'left' | 'right' | 'center'
And 47 more cards. Study the whole deck free
Articles about this deck
More Programming decks
See all- 🌐
APIs: REST, GraphQL & HTTP Status Codes
108 cards · 🇺🇸 English
REST and GraphQL API concepts plus common HTTP status codes.
- 🎨
CSS: Box-Modell, Selektoren & Media Queries
129 cards · 🇺🇸 English
Das CSS-Box-Modell, Selektortypen, Media Queries und Animationen.
- 📄
HTML : balises et attributs
99 cards · 🇺🇸 English
Éléments HTML essentiels et leurs attributs.
- 🎨
CSS: Box Model, Selectors & Media Queries
129 cards · 🇺🇸 English
The CSS box model, selector types, media queries, and animations.
- 🔒
Web Security: OWASP & Authentication
35 cards · 🇺🇸 English
Common web vulnerabilities (OWASP Top 10) and authentication concepts.
- 🎨
CSS : Flexbox et Grid
58 cards · 🇺🇸 English
Mise en page avec CSS Flexbox et Grid.
