bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/TypeScript/TypeScript Core
TypeScript•TypeScript Core

TypeScript 5.x Updates

TypeScript is actively maintained and updated by Microsoft.

In version 5.x a lot of utility and quality of life updates were made.

This chapter covers the most popular updates to allow stricter and more flexible type safety.

As a reminder these features will only be available in 5.x+

Template Literal Types

Template Literal Types now allows us to create more precise types using template literals.

We can define custom types that depend on the actual values of strings at compile time.

Example

type Color = "red" | "green" | "blue";
type HexColor<T extends Color> = `#${string}`;
// Usage: let myColor: HexColor<"blue"> = "#0000FF";

Index Signature Labels

Index Signature Labels allows us to label index signatures using computed property names.

It helps in providing more descriptive type information when working with dynamic objects.

Example

type DynamicObject = { [key: `dynamic_${string}`]: string };
// Usage: let obj: DynamicObject = { dynamic_key: "value" };

5.x also now supports native JavaScript private fields.

The TypeScript 'private' still works as discussed in Classes section.

Previous

TypeScript Definitely Typed

Next

TypeScript Configuration

This chapter

Overview
40

Lessons

241m

Read time

1. TypeScript Tutorial2. TypeScript Introduction3. TypeScript Getting Started4. TypeScript Simple Types5. TypeScript Explicit Types and Inference6. TypeScript Special Types7. TypeScript Arrays8. TypeScript Tuples9. TypeScript Object Types10. TypeScript Enums11. TypeScript Type Aliases and Interfaces12. TypeScript Union Types13. TypeScript Functions14. TypeScript Casting15. TypeScript Classes16. TypeScript Basic Generics17. TypeScript Utility Types18. TypeScript Keyof19. TypeScript Null & Undefined20. TypeScript Definitely Typed21. TypeScript 5.x Updates22. TypeScript Configuration23. TypeScript with Node.js24. TypeScript with React25. TypeScript Tooling26. TypeScript Advanced Types27. TypeScript Type Guards28. TypeScript Conditional Types29. TypeScript Mapped Types30. TypeScript Type Inference31. TypeScript Literal Types32. TypeScript Namespaces33. TypeScript Index Signatures34. TypeScript Declaration Merging35. TypeScript Async Programming36. TypeScript Decorators37. TypeScript in JavaScript Projects (JSDoc)38. TypeScript Migration Guide39. TypeScript Error Handling40. TypeScript Best Practices

On this page

Template Literal TypesIndex Signature Labels