Support our educational content for free when you purchase through links on our site. Learn more
TypeScript Types: 15 Essentials Every Developer Should Know 🧩
TypeScript types help you catch mistakes before your code runs, and the best starting point is enabling strict checking, learning the core types, and letting inference do the routine work. They describe the values your code expects, from a string in a form field to the exact states a game character can enter.
If you’re exploring TypeScript in Angular, building an app, or protyping a Phaser game, types can make changes safer and editor feedback more useful. They won’t validate data coming from an API at runtime, though—that distinction is easy to miss, and it matters.
We’ve seen a small type catch a surprisingly large bug: a game state represented as string accepted "plaing" instead of "playing". A literal union makes that typo a compile-time error. No dramatic debugging session required; the compiler simply refuses to let the typo sneak into the game.
Key Takeaways
- TypeScript types describe the values your code can use and help the compiler detect many mistakes before execution.
- Start with primitives, arrays, object types, unions, and function types; add generics and advanced type operators when they solve a real problem.
- Prefer inference when TypeScript already knows the type, and use explicit annotations where they clarify intent or define a boundary.
- Enable
strictchecks for stronger feedback, especially aroundnull,undefined, and implicitany. - Use
unknowninstead ofanyfor untrusted values, then narrow or validate before using them. - Types disappear when TypeScript compiles to JavaScript. Validate external data at runtime when correctness or security depends on it.
Table of Contents
- ⚡️ Quick Tips and Facts About TypeScript Types
- 📚 TypeScript Type System: Background and Design
- 🧭 TypeScript Types at a Glance
- Static Typing, Type Inference, and Type Checking
- Types at Compile Time vs. Values at Runtime
- Structural Typing and Type Compatibility
- 📝 Type Anotations and Type Inference
- Annotating Variables and Constants
- When TypeScript Infers a Type
- Avoiding Unecessary Anotations
- 🔤 Primitive Types and JavaScript Values
- string, number, and boolean
- bigint and symbol
- null and undefined
- void, never, and object
- 📦 Arrays, Tuples, and Readonly Collections
- Array Types and Generic Array Syntax
- Tuples and Named Tuple Elements
- Readonly Arrays and Tuples
- 🏗️ Object Types and Property Modifiers
- Declaring Object Shapes
- Optional Properties
- Readonly Properties
- Excess Property Checks and Object Literals
- Index Signatures and Dynamic Keys
- 🔀 Union and Intersection Types
- Defining Union Types
- Working with Union Types
- Intersection Types for Combining Shapes
- Discriminated Unions and Exhaustive Checks
- 🏷️ Type Aliases and Interfaces
- Creating Reusable Type Aliases
- Declaring Interfaces
- Type Aliases vs. Interfaces: Key Differences
- Extending, Merging, and Composing Types
- ✨ Literal Types and Narrowing
- String, Number, and Boolean Literal Types
- Literal Inference, const Assertions, and as const
- Narrowing Types with typeof and Truthiness
- Narrowing with in, instanceof, and Equality Checks
- User-Defined Type Guards and Assertion Functions
- 🛠️ Functions and Function Types
- Parameter Type Anotations
- Return Type Anotations
- Optional, Default, and Rest Parameters
- Function Type Expressions and Call Signatures
- Anonymous Functions and Contextual Typing
- Overloads, this Parameters, and Callback Types
- 🧩 Generics and Reusable Type Patterns
- Generic Functions and Type Parameters
- Generic Constraints and keyof
- Default Type Parameters and Inference
- Generic Interfaces, Classes, and Type Aliases
- 🪄 Type Operators and Advanced Types
- keyof, typeof, and Indexed Access Types
- Conditional Types and infer
- Mapped Types and Property Modifiers
- Template Literal Types
- Recursive Types and Utility Types
- ⚠️ any, unknown, and Safer Alternatives
- Why any Weakens Type Safety
- Using unknown for Untrusted Values
- never for Impossible States
- Choosing Between any, unknown, and never
- 🎭 Type Assertions and Type Safety
- Type Assertions with as
- Non-Null Assertion Operator (!)
- When Assertions Are Unsafe
- 🚦 null, undefined, and Strict Null Checking
- How strictNullChecks Changes Type Behavior
- Optional Chaining and Nullish Coalescing
- Handling Nullable Values Safely
- 🔢 Enums and Alternatives
- Numeric and String Enums
- Const Enums and Runtime Considerations
- When to Use Union Literals Instead
- 🧰 TypeScript Utility Types
- Partial, Required, and Readonly
- Pick, Omit, and Record
- Exclude, Extract, and NonNullable
- Parameters, ReturnType, and Awaited
- ⚙️ TypeScript Configuration for Reliable Types
- strict and strictNullChecks
- noImplicitAny and Related Safety Options
- Type Checking with tsconfig.json
- 🔌 Types for Modules, Libraries, and JavaScript
- Importing and Exporting Types
- Declaration Files and DefinitelyTyped
- Typing JavaScript with JSDoc
- Augmenting Modules and Global Types
- 🧪 Practical TypeScript Type Examples
- Typing API Responses and JSON
- Typing React Props and Events
- Typing Promises and Async Functions
- Modeling State and Result Types
- 🐛 Common Type Errors and How to Fix Them
- Type Is Not Assignable
- Possibly Undefined or Null
- Property Does Not Exist on Type
- Type Inference Is Too Broad or Too Narrow
- ✅ TypeScript Types Best Practices
- ❓ Frequently Asked Questions About TypeScript Types
- What are types in TypeScript?
- What is the difference between a type and an interface?
- What is the difference between any and unknown?
- Are TypeScript types available at runtime?
- How do I check a type at runtime?
- 🏁 Conclusion
- 🔗 Recommended Links
- 📖 Reference Links
Table of Contents
- ⚡️ Quick Tips and Facts About TypeScript Types
- 📚 TypeScript Type System: Background and Design
- 🧭 TypeScript Types at a Glance
- Static Typing, Type Inference, and Type Checking
- Types at Compile Time vs. Values at Runtime
- Structural Typing and Type Compatibility
- 📝 Type Anotations and Type Inference
- Annotating Variables and Constants
- When TypeScript Infers a Type
- Avoiding Unecessary Anotations
- 🔤 Primitive Types and JavaScript Values
- string, number, and boolean
- bigint and symbol
- null and undefined
- void, never, and object
- 📦 Arrays, Tuples, and Readonly Collections
- Array Types and Generic Array Syntax
- Tuples and Named Tuple Elements
- Readonly Arrays and Tuples
- 🏗️ Object Types and Property Modifiers
- Declaring Object Shapes
- Optional Properties
- Readonly Properties
- Excess Property Checks and Object Literals
- Index Signatures and Dynamic Keys
- 🔀 Union and Intersection Types
- Defining Union Types
- Working with Union Types
- Intersection Types for Combining Shapes
- Discriminated Unions and Exhaustive Checks
- 🏷️ Type Aliases and Interfaces
- Creating Reusable Type Aliases
- Declaring Interfaces
- Type Aliases vs. Interfaces: Key Differences
- Extending, Merging, and Composing Types
- ✨ Literal Types and Narrowing
- String, Number, and Boolean Literal Types
- Literal Inference, const Assertions, and as const
- Narrowing Types with typeof and Truthiness
- Narrowing with in, instanceof, and Equality Checks
- User-Defined Type Guards and Assertion Functions
- 🛠️ Functions and Function Types
- Parameter Type Anotations
- Return Type Anotations
- Optional, Default, and Rest Parameters
- Function Type Expressions and Call Signatures
- Anonymous Functions and Contextual Typing
- Overloads, this Parameters, and Callback Types
- 🧩 Generics and Reusable Type Patterns
- Generic Functions and Type Parameters
- Generic Constraints and keyof
- Default Type Parameters and Inference
- Generic Interfaces, Classes, and Type Aliases
- 🪄 Type Operators and Advanced Types
- keyof, typeof, and Indexed Access Types
- Conditional Types and infer
- Mapped Types and Property Modifiers
- Template Literal Types
- Recursive Types and Utility Types
- ⚠️ any, unknown, and Safer Alternatives
- Why any Weakens Type Safety
- Using unknown for Untrusted Values
- never for Impossible States
- Choosing Between any, unknown, and never
- 🎭 Type Assertions and Type Safety
- Type Assertions with as
- Non-Null Assertion Operator (!)
- When Assertions Are Unsafe
- 🚦 null, undefined, and Strict Null Checking
- How strictNullChecks Changes Type Behavior
- Optional Chaining and Nullish Coalescing
- Handling Nullable Values Safely
- 🔢 Enums and Alternatives
- Numeric and String Enums
- Const Enums and Runtime Considerations
- When to Use Union Literals Instead
- 🧰 TypeScript Utility Types
- Partial, Required, and Readonly
- Pick, Omit, and Record
- Exclude, Extract, and NonNullable
- Parameters, ReturnType, and Awaited
- ⚙️ TypeScript Configuration for Reliable Types
- strict and strictNullChecks
- noImplicitAny and Related Safety Options
- Type Checking with tsconfig.json
- 🔌 Types for Modules, Libraries, and JavaScript
- Importing and Exporting Types
- Declaration Files and DefinitelyTyped
- Typing JavaScript with JSDoc
- Augmenting Modules and Global Types
- 🧪 Practical TypeScript Type Examples
- Typing API Responses and JSON
- Typing React Props and Events
- Typing Promises and Async Functions
- Modeling State and Result Types
- 🐛 Common Type Errors and How to Fix Them
- Type Is Not Assignable
- Possibly Undefined or Null
- Property Does Not Exist on Type
- Type Inference Is Too Broad or Too Narrow
- ✅ TypeScript Types Best Practices
- ❓ Frequently Asked Questions About TypeScript Types
- How do TypeScript types integrate with popular game engines like Unity or Phaser?
- What is the difference between TypeScript types and interfaces in app development?
- How do you create custom TypeScript types for game objects?
- What advanced TypeScript types should app developers know?
- Can TypeScript types help prevent bugs in game programming?
- How do TypeScript types improve app development efficiency?
- What are the most common TypeScript types used in game development?
- What is the difference between JavaScript types and TypeScript types?
- What is a type in TypeScript?
- What are TypeScript types, and why should app developers use them?
- How do you define custom types in TypeScript for an app?
- How do you type React component props with TypeScript?
- What are generics in TypeScript, and when should app developers use them?
- How do you use TypeScript types to model game characters and items?
- 🏁 Conclusion
- 🔗 Recommended Links
- 📖 Reference Links




