TypeScript 7.1 Beta ships new compiler API, content mappers and speed gains
Brief
TypeScript 7.1 Beta is out, adding a new compiler API, first-class content mappers for single-file component formats, and performance improvements over TypeScript 7.0.
Language and library changes
- Ambient module declarations can now include import attributes, e.g. declare module "*" with { type: "css" }, so imports must carry the required attributes and get types based on them.
- Source phase imports (import source, import.source()) return an AbstractModuleSource; WebAssembly source imports can be passed to WebAssembly.instantiate. Requires esnext/nodenext/preserve module settings.
- es2026 is now a stable --target and --lib option, adding Math.sumPrecise, Iterator.concat, JSON.rawJSON, Error.isError, Map getOrInsert and Uint8Array base64/hex methods. esnext adds Promise.allKeyed, Iterator.zip, chunks, join and includes.
New compiler API
- Entry points: typescript/sync, typescript/async, typescript/fs, typescript/ast, typescript/ast/is and typescript/ast/factory.
- The API does not discover or load tsconfig.json and does not support --project; filenames and options are passed explicitly.
- Snapshots model state over time and can be updated incrementally; API, Program and Snapshot objects are Disposables and must be closed or declared with using.
- File system helpers: createFileSystem, createFileSystemWithLib and createFileSystemLayer for virtual and layered files.
Content mappers
- Registered per file extension in tsconfig.json via a contentMappers array referencing a package and extensions.
- Running tsc requires the --runExternalCode flag; VS Code needs workspace trust and content mapper permissions, with a js/ts.contentMappers.enabled setting.
- Prototypes exist for Astro, CSS Modules, Ember, MDX, Svelte and Vue.
Performance and next steps
- Benchmarks under --noEmit with 4 checker threads: mui-docs 22.2s to 11.9s (1.9x), t3code-server 26.5s to 19.1s, sentry 19.6s to 15.1s, vscode 21.6s to 17.7s.
- Memory reductions range from 15.8% (bluesky) to 49.6% (mui-docs).
- TypeScript 7.1 is stricter about distributive type parameters, which can surface new errors. A release candidate is expected in about a month.
Generated by AI from the original article. Check the source for full details.