Skip to content
Tutorials Center
My learning

Topics

Lesson 60 of 96 ยท Modern Features

What's New in TypeScript 5.x, 6.0 and 7.0

A guided tour of modern TypeScript - the headline features of every 5.x release, the 6.0 deprecations, the native Go compiler in 7.0 and how to upgrade safely.

TypeScript ships a new minor version roughly every three months. Each one adds a few headline features and a long list of smaller improvements, and after a few years it's easy to lose track of what's "modern". Code written for TypeScript 4 still compiles today, but it often works harder than it needs to.

This lesson is a tour of the releases that shaped the TypeScript you write now: the ten 5.x versions, the 6.0 "bridge" release that cleaned up old options, and 7.0, which rewrote the compiler itself in Go. For each version you'll see the features that change everyday code, most of them as runnable examples. Everything here works in our editor, which runs the TypeScript 7.0.2 compiler.

You don't need to memorize version numbers. The useful skill is recognizing these features when you read code, and knowing that an old workaround now has a built-in replacement.

The big picture

Version Released Headline features
5.0 March 2023 Standard decorators, const type parameters, --moduleResolution bundler, --verbatimModuleSyntax
5.1 June 2023 Functions returning undefined need no return, unrelated getter/setter types
5.2 August 2023 using declarations, decorator metadata, typed copying array methods
5.3 November 2023 Import attributes, switch (true) narrowing
5.4 March 2024 NoInfer, narrowing preserved in closures, Object.groupBy types
5.5 June 2024 Inferred type predicates, regex syntax checking, --isolatedDeclarations
5.6 September 2024 Errors for always-truthy checks, iterator helper types
5.7 November 2024 Never-initialized variable checks, --rewriteRelativeImportExtensions
5.8 February 2025 --erasableSyntaxOnly, checks for each branch of a returned conditional
5.9 August 2025 Leaner tsc --init, import defer
6.0 2026 The last JavaScript-based compiler; deprecates legacy options
7.0 2026 The native compiler written in Go, about 10 times faster

The release months for 6.0 and 7.0 are deliberately vague here; what matters is that 6.0 prepares projects for 7.0, and that 7.0 speaks the same language as 6.0.

TypeScript 5.0: decorators and const type parameters

Standard decorators

TypeScript had decorators for years, but behind the experimentalDecorators flag and based on an old proposal. 5.0 implemented the standard TC39 decorators, which need no flag at all. A decorator is a function that receives the thing it decorates plus a context object:

TypeScript A standard method decorator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

It prints:

TEXT
-> add(2, 3)
<- add returned 5

The Decorators lesson covers class, field and accessor decorators in depth, and explains why frameworks like Angular still use the legacy flavor.

const type parameters

When a generic function receives ['a', 'b'], TypeScript normally infers string[]. Callers used to add as const to keep the literals. With a const modifier on the type parameter, the function asks for literal inference instead:

TypeScript const type parameters keep literals

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

The output is /home 2 2. The line const first: Precise[0] = '/home' compiles only because Precise[0] is the literal type "/home". See generic constraints for more about const type parameters.

Module settings for modern tools

Two options from 5.0 show up in almost every new tsconfig.json (see the tsconfig lesson):

  • "moduleResolution": "bundler" resolves imports the way Vite, esbuild and webpack do (package exports, no file extensions required).
  • "verbatimModuleSyntax": true makes the emitted imports match what you wrote: an import type is always removed, and a plain import is always kept. It replaced the confusing importsNotUsedAsValues and preserveValueImports flags. The Modules lesson shows it in action.

5.0 also made every enum a union of its members, allowed extends with an array of config files in tsconfig.json, and added export type *.

TypeScript 5.1 to 5.3: smaller conveniences

  • 5.1 lets a function whose return type is undefined end without a return statement, and allows a getter and setter to have unrelated types (for example a setter that accepts string | number while the getter returns string).
  • 5.2 added the using keyword (next section) and typed the new copying array methods toSorted(), toReversed(), toSpliced() and with(), which return a new array instead of mutating the original.
  • 5.3 supports import attributes (import data from './data.json' with { type: 'json' }) and narrows inside switch (true), a pattern some people prefer to long if/else chains.
TypeScript switch (true) narrowing and copying array methods

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

It prints:

TEXT
text of length 5
number 3.1
list: alpha, mu, zeta
original is unchanged: [ 'zeta', 'alpha', 'mu' ]

Inside each case, value is narrowed just as it would be after an if. In the default branch TypeScript knows only string[] is left, so value.toSorted() is allowed.

TypeScript 5.2: using declarations

using brings explicit resource management to JavaScript: a variable declared with using is cleaned up automatically when its block ends, even when an exception is thrown. The object only needs a [Symbol.dispose]() method:

TypeScript using cleans up at the end of the block

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

The output shows that resources are disposed in reverse order, like nested try/finally blocks:

TEXT
open a.txt
open b.txt
working with a.txt and b.txt
close b.txt
close a.txt
done

The full story, including await using and DisposableStack, is in using declarations.

TypeScript 5.4: NoInfer and smarter closures

NoInfer

Sometimes a type parameter appears in several places, and you want only one of them to decide what it is. Wrap the others in NoInfer<T>:

TypeScript NoInfer blocks inference from one argument (fails on purpose)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

This one fails on purpose. Without NoInfer, TypeScript would infer C as "red" | "green" | "blue" from both arguments and accept the call. With it, C comes only from options, so the second call is rejected:

TEXT
main.ts(6,41): error TS2345: Argument of type '"blue"' is not assignable to parameter of type '"green" | "red"'.

Narrowing that survives into closures

Before 5.4, narrowing was forgotten inside callbacks, because TypeScript couldn't be sure the variable wasn't reassigned later. Now, if a let variable or parameter isn't assigned after the closure is created, the narrowing carries over:

TypeScript
function greetAll(names: string[], prefix?: string) {
  if (!prefix) {
    prefix = 'Hello';
  }
  // 5.4+: prefix is string here, even inside the arrow function
  return names.map((name) => `${prefix.trim()}, ${name}`);
}

5.4 also typed Object.groupBy() and Map.groupBy(), which group an array by a key function.

TypeScript 5.5: inferred type predicates

This is one of the most loved recent features. TypeScript now infers that a function like x => x !== undefined is a type predicate (x is T), so filtering finally narrows the array type without help:

TypeScript filter now narrows by itself

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

It prints [ 90, 75, 88 ] 253 [ 'tree', 'river' ]. The two Expect<Equal<...>> lines (the checker introduced in utility types) prove that present is number[] and words is string[]. In TypeScript 5.4, both would have kept undefined or null in their element types, and sum + s would have been an error.

Notice that isLong is not inferred as a predicate: when it returns false, the word might be a short string rather than null, so "false means null" isn't true. TypeScript only infers a predicate when both the true and the false side are exact. The type predicates lesson explains the rules.

Other 5.5 additions:

  • Regular expression checking. Syntax errors in regex literals, like an unclosed group, are now compile errors.
  • Narrowing of obj[key] when both obj and key are constants.
  • --isolatedDeclarations, which requires explicit types on exports so tools can generate .d.ts files without running the type checker.
  • Types for the new Set methods union(), intersection(), difference() and friends.

TypeScript 5.6 and 5.7: catching more mistakes

These releases made the checker flag code that is almost certainly a bug:

TypeScript Checks added in 5.5, 5.6 and 5.7 (fails on purpose)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Nothing runs; you get three errors:

TEXT
main.ts(1,22): error TS1005: ')' expected.
main.ts(4,7): error TS2872: This kind of expression is always truthy.
main.ts(12,15): error TS2454: Variable 'total' is used before being assigned.
  • The regex /(\d+/ has an unclosed group (5.5).
  • if (() => age >= 18) tests a function object, which is always truthy. Since 5.6, TypeScript reports conditions that can be proven always truthy or always nullish from their syntax alone, such as arrow functions, regex literals and object literals. (The fix is if (age >= 18).)
  • total is declared but never assigned anywhere, so reading it inside report() is an error (5.7). Before 5.7, TypeScript gave up on variables read inside other functions.

5.6 also gave iterators proper types for the ES2025 iterator helpers (.map(), .filter(), .take() directly on iterators), covered in iterators and generators. 5.7 added --rewriteRelativeImportExtensions, which turns import './util.ts' into import './util.js' in the output, so the same source works with Node's type stripping and with tsc.

TypeScript 5.8 and 5.9: erasable syntax

Node.js 22.6 and later can run .ts files directly by stripping the types, which you'll try in TypeScript with Node.js. Stripping only works for syntax that can be deleted without changing behavior. enum, namespace with code inside, and constructor parameter properties generate JavaScript, so they can't simply be erased.

5.8 added --erasableSyntaxOnly, which reports exactly those constructs:

TypeScript
// With "erasableSyntaxOnly": true in tsconfig.json
enum Direction { Up, Down }                 // error TS1294
class Point {
  constructor(public x: number) {}          // error TS1294
}

Error TS1294 reads "This syntax is not allowed when 'erasableSyntaxOnly' is enabled." Our editor doesn't enable this flag, so enums and parameter properties work in the TryIts, as the Enums lesson shows.

5.8 also checks each branch of a conditional expression in a return statement against the return type, which catches mistakes that used to slip through as any. 5.9 made tsc --init generate a short, modern tsconfig.json and added import defer for modules that should only run when first used.

TypeScript 6.0: the bridge release

TypeScript 6.0 is the last version whose compiler is written in TypeScript itself. Its main job is to get projects ready for 7.0 by deprecating options the native compiler will not support. With 6.0 they still work, but produce deprecation errors that you can temporarily silence with "ignoreDeprecations": "6.0". In 7.0 they are gone.

Deprecated in 6.0, removed in 7.0 Use instead
"target": "es5" es2015 or newer (all current browsers support ES2015+)
"moduleResolution": "node" (also called node10) nodenext for Node.js, bundler for bundled apps
"moduleResolution": "classic" (already removed in 6.0) nodenext or bundler
"outFile" A bundler
"baseUrl" Relative paths entries, or package.json imports
"module": "amd", "umd", "system" esnext, nodenext or preserve
"downlevelIteration" Not needed with ES2015+ targets

6.0 also updated several defaults to match modern projects. The safest approach, for any version, is to set the important options (strict, target, module, moduleResolution) explicitly in your tsconfig.json instead of relying on defaults.

TypeScript 7.0: the native compiler

TypeScript 7.0 is a port of the compiler from TypeScript to Go. The language is the same as 6.0: the same syntax, the same type system and, apart from rare edge cases, the same errors. What changed is speed:

  • A full type check of a large project is typically around 10 times faster, thanks to native code and type checking spread across CPU cores.
  • Editors start faster and stay responsive in huge codebases, because the language service is now native too and speaks the standard Language Server Protocol.
  • Memory use is lower.

During development the native compiler was available as a preview package with a tsgo command; in 7.0 it is simply tsc. For most projects, upgrading means:

  1. Upgrade to 6.0 first and fix every deprecation error.
  2. Install 7.0 and run tsc --noEmit to compare the errors with 6.0.
  3. Check your tools. Anything that used the old JavaScript compiler API (some linters, custom transformers, older build plugins) needs a version that supports 7.0. Plain type checking and emitting need nothing special.
Terminal
npm install --save-dev typescript@latest
npx tsc --version
npx tsc --noEmit

How to keep up

  • Read the release notes for each new version: every release explains its features with examples, and breaking changes are listed at the end.
  • Raise target and lib over time, so you get types for new JavaScript features such as Object.groupBy or Set.prototype.union.
  • When you see an old pattern, check whether a newer feature replaces it: as const at every call site (const type parameters), hand-written type guards for filter (inferred predicates), try/finally cleanup (using), annotations that throw away detail (satisfies, added in 4.9).

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which feature lets filter((x) => x !== undefined) return number[] instead of (number | undefined)[]?

    Since 5.5, TypeScript infers that a callback like x => x !== undefined is a type predicate, so filter narrows the element type.
  2. 2. In function f<T>(a: T[], b: NoInfer<T>), what does NoInfer do?

    NoInfer marks a position that must not contribute to inference. b is still checked against the T inferred from a.
  3. 3. Why does --erasableSyntaxOnly reject enums?

    Type stripping just removes type syntax. An enum creates a runtime object, so removing it would change the program. Enums are still fully supported by tsc.
  4. 4. What is the main change in TypeScript 7.0?

    7.0 is a native port of the compiler. Code that compiles cleanly with 6.0 (without deprecated options) is expected to compile the same way with 7.0.
  5. 5. Your tsconfig.json has "moduleResolution": "node". What should you do before moving to TypeScript 7.0?

    node (node10) resolution was deprecated in 6.0 and removed in 7.0, and classic resolution was already removed in 6.0. baseUrl was removed in 7.0 too.

Summary

  • 5.0 brought standard decorators, const type parameters and the modern module options bundler and verbatimModuleSyntax.
  • 5.2 added using declarations for automatic cleanup; 5.3 narrowing in switch (true) and import attributes.
  • 5.4 added NoInfer and kept narrowing inside closures; 5.5 inferred type predicates, so filter narrows by itself, plus regex checking.
  • 5.6 and 5.7 catch always-truthy conditions and never-assigned variables; 5.8 added --erasableSyntaxOnly for Node's type stripping.
  • 6.0 deprecates legacy options such as target: es5, moduleResolution: node, outFile and baseUrl.
  • 7.0 is the native Go compiler: same language as 6.0, roughly ten times faster. Upgrade through 6.0 and check tools that use the compiler API.

Next: TypeScript with Node.js