← Back to BlogArticle

TypeScript 5.8: New Features Every Developer Should Know

TypeScript 5.8 pairs perfectly with React 19 and Next.js 16. This guide covers the new features that will improve your developer experience and type safety.

const Type Parameters

The biggest new feature — generic functions now infer as const by default:

function getConfig<T>() {
  return { config: {} } as T
}

// Before: needed 'as const'
const config1 = getConfig<{ theme: 'dark' }>()

// TS 5.8: infers as const automatically
const config2 = getConfig<{ theme: 'dark' }>()

Improved Type Narrowing

Better inference with typeof and instanceof:

function processValue(value: string | number) {
  if (typeof value === 'string') {
    return value.toUpperCase() // TypeScript knows it's string
  }
  return value.toFixed(2) // TypeScript knows it's number
}

React 19 Support

First-class support for React 19 features:

import { use } from 'react'
import { cache } from 'react'

// Automatic memoization with use + cache
const getData = cache(async () => {
  const data = await fetchData()
  return data
})

function Component() {
  const data = use(getData())
  return <div>{data.name}</div>
}

No Longer Need 'any' Workarounds

Many patterns that required 'any' now work with proper types:

// Event handlers are properly typed
document.addEventListener('click', (e) => {
  e.preventDefault() // Properly typed as MouseEvent
})

// Generic event types work
function handler<E extends Event>(e: E) {
  console.log(e.target) // Properly typed
}

Migration Tips

  • Update to Node.js 20.9+ (TS 5.8 requirement)
  • Remove 'as const' where now automatic
  • Update @types/react to latest
  • Run tsc --noEmit to check for breaking changes

Key Takeaways

  • const type parameters = less 'as const' needed
  • Better type narrowing with typeof/instanceof
  • Native React 19 use() hook support
  • Node.js 20.9+ required