bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/TypeScript/TypeScript Core
TypeScript•TypeScript Core

TypeScript 5.x Updates

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind TypeScript 5.x Updates?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ Color = "red" | "green" | "blue";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Index Signature Labels
Template Literal Types
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