Typorithm · hard

13. TypeScript 6 migration: explicit defaults and deprecations

typescriptstable-typescriptinterviewindependent-practice
Saved on this device
Full lesson · 4 learning steps Open any exercise for focused practice
1

Step 1 of 4 · intro card

13. TypeScript 6 migration: explicit defaults and deprecations

0%

Concept and contract

Plan a reproducible compiler migration instead of suppressing configuration diagnostics.

This lesson is versioned as of 5 November 2026. TypeScript 6 is the compatibility bridge to the native TypeScript 7 toolchain. Treat migration as a controlled change to checking, configuration and dependent tools, with the application’s runtime behavior tested independently.

Begin from a clean baseline with a pinned compiler and lockfile. Record the effective configuration and current diagnostics. Upgrade the compiler in an isolated branch before changing unrelated dependencies, so a new failure has a small, reviewable cause.

Mechanism and worked example

TypeScript 6 changes defaults including strictness, rootDir and automatic inclusion of ambient types.

TypeScript 6 changes defaults including strictness, rootDir and automatic inclusion of ambient types. Set important options explicitly rather than depending on whichever version a developer’s editor happens to load. The worked example keeps the data contract unchanged while making its null handling visible.

Review deprecated configuration such as node10 resolution, baseUrl and ES5 targeting before moving to 7, where removed options become hard errors. Choose NodeNext or Bundler according to the actual host; changing a flag without checking emitted execution is not a complete migration.

Complete worked example

typescript

function normalizeTitle(value:string|null):string{return value===null?"":value.trim();}
const title=normalizeTitle(" QA ");
Reasoning
The behavior fixture is intentionally small so compiler and configuration changes remain separable.

Counterexamples and common mistakes

The rejected null assignment demonstrates a strictness issue that an older loose baseline may have concealed.

The rejected null assignment demonstrates a strictness issue that an older loose baseline may have concealed. Repair the domain contract or add a real branch; do not scatter non-null assertions merely to regain a green build. Each diagnostic should correspond to a documented assumption.

ignoreDeprecations can temporarily silence warnings in a compatible release, but it does not implement removed behavior or prepare an application for the next compiler. Keep any temporary suppression bounded and tracked, with an explicit migration path.

Rejected counterexample: expected compiler diagnostic

typescript

// @ts-expect-error strictNullChecks rejects null as string.
const title:string=null;
Reasoning
Strict null checking exposes an assumption; a real branch or honest union should resolve it.

Independent practice

Create two explicit configurations for the same small project: a browser-bundler setup and a direct Node ESM setup.

Create two explicit configurations for the same small project: a browser-bundler setup and a direct Node ESM setup. Pin strict, rootDir, types, target and module choices. Start with one source file, then add a second import and verify the actual emitted host behavior.

Use the small normalizeTitle implementation as a baseline behavior fixture. Add a nullable input case and preserve its output during the compiler change. Optional extension: compare declaration output with stableTypeOrdering when preparing a 6-to-7 transition.

Step 1: Record the current effective configuration. Step 2: Preserve the explicit missing-title behavior under both compilers.

Practice starter: solve before reading the solution

typescript

function normalizeTitle(value:string|null|undefined):string{throw new Error("TODO: explicit missing-value policy");}
Reasoning
Keep one baseline function stable while comparing explicit host configurations.
  • Hint 1: A suppression does not replace deprecated behavior.
  • Hint 2: Test the emitted host as well as diagnostics.

Solution, tests and trade-offs

The solution’s nullable branch makes the runtime policy explicit: missing text becomes an empty label, present text is trimmed.

The solution’s nullable branch makes the runtime policy explicit: missing text becomes an empty label, present text is trimmed. That policy is independent of the compiler migration. The same accepted and rejected fixtures should run under both supported compiler versions.

Compare diagnostics before and after the upgrade, then inspect configuration and declaration diffs. Run runtime assertions even when types match. Native compiler compatibility aims do not prove that a changed module configuration still emits the same runnable package layout.

Practice solution and acceptance checks

typescript

function normalizeTitle(value:string|null|undefined):string{return value==null?"":value.trim();}

// Acceptance checks
if(normalizeTitle(undefined)!==""||normalizeTitle(null)!==""||normalizeTitle(" QA ")!=="QA")throw new Error("migration behavior");
Reasoning
The missing-value policy is executable and testable under both supported compilers.

Interview reasoning and next step

In interviews, describe a migration checklist grounded in evidence: pinned baseline, explicit options, dependent tooling compatibility, diagnostic review and runtime smoke tests.

In interviews, describe a migration checklist grounded in evidence: pinned baseline, explicit options, dependent tooling compatibility, diagnostic review and runtime smoke tests. Explain why disabling strictness or suppressing deprecations can hide rather than resolve a contract problem.

Next, adopt the native 7 compiler deliberately. Keep tools that embed the older compiler API on a compatible package until their integration supports the new API rather than assuming a CLI replacement updates every plugin.

Optional stretch — after the core task works: Compare stable declaration ordering for the migration.

Plan a reproducible compiler migration instead of suppressing configuration diagnostics.