TypeScript 7.0 made the headlines for being a native port, and the follow-up beta is where the pieces tool authors were missing start to arrive. If you write apps, TypeScript 7.1 is a modest release with a few sharp conveniences. If you write tooling, it may be the one you have been waiting for.

Daniel Rosenwasser, Principal Product Manager on the TypeScript team, announced the 7.1 beta on the TypeScript dev blog. I read the announcement carefully, and here is what I think matters, in the order I would try it.

How to install the beta

The announcement gives the command directly: npm install -D typescript@beta. As with any beta, I would not run it on the main branch of a production project. Use a feature branch or a CI job that runs your type check against the beta alongside the stable version. That gives you early warning without changing what ships.

Prerequisites: Node.js with npm, an existing TypeScript project and a lockfile you can restore. If the beta breaks something, reverting is a matter of reinstalling your pinned version.

Import attributes in ambient modules

This one fixes a long-standing annoyance for anyone who imports non-code files. Import attributes are metadata attached to import statements, such as the with { type: "json" } clause. Runtimes and bundlers use them to decide how to interpret a file, and the type attribute has become the de facto standard.

The TypeScript team lists several import types in play: type: "json", a proposal for type: "text" that returns a string, a proposal for type: "bytes" that returns a Uint8Array, and type: "css" for CSS style sheets, which browsers have supported for a few years.

The old way to type these imports was an ambient module declaration with a wildcard, such as declare module "*.css". The team explains why that falls short: it does not account for import attributes at all, it is repetitive (you redeclare for .txt and .md even though both use type: "text") and runtimes may treat the same file differently depending on the attribute.

TypeScript 7.1 lets you declare modules with attributes:

TypeScriptCopy 

declare module "*" with { type: "css" } {
const content: CSSStyleSheet;
export default content;
}

You get an error if you import a file without the required attribute, and the correct type based on the attribute. Two caveats from the announcement: imports matching these declarations are not validated against files on disk, and the declarations are not shipped as part of TypeScript's built-in libraries. The team recommends libraries not include them in published packages, so end users declare them in their own projects.

My view: if you import CSS, text or binary files, add these declarations to a global .d.ts file in your app. That is a five-minute change that removes a whole class of "forgot the attribute" bugs.

Source phase imports

TypeScript 7.1 also supports source phase imports, a proposed ECMAScript feature. The syntax is import source SomeModule from "some-module", and only default imports can be written this way. You get back an inert object representing the module after it has been parsed, but before its imports are loaded or any code can run.

The main use today is WebAssembly. A source import of a .wasm file gives you a WebAssembly.Module that you can pass directly to WebAssembly.instantiate. The announcement notes WebAssembly source imports are already supported in recent versions of Node.js. There is also a dynamic form, import.source("./super-fast-thing.wasm"), and source imports retain identity, so the same source imported twice compares equal.

For JavaScript files, temper your expectations. The team says you cannot do much with a source import of a JavaScript file yet, and many environments and tools do not support it. You need an appropriate --module setting, such as esnext, nodenext or preserve, and the right esnext option in --lib or --target. Unless you are working with WebAssembly, I would watch this one rather than adopt it.

es2026 becomes a stable target

TypeScript 7.1 supports es2026 as a stable --target and --lib option. Per the announcement, the significant changes are library additions. Stabilised items in --lib es2026 include:

  • Math.sumPrecise()
  • Iterator.concat()
  • JSON.rawJSON() and a JSON.parse() overload for parsing with the original text
  • Error.isError()
  • getOrInsert() and getOrInsertComputed() on Map.prototype and WeakMap.prototype
  • toBase64(), setFromBase64(), toHex() and setFromHex() on Uint8Array.prototype, plus Uint8Array.fromHex() and Uint8Array.fromBase64()
  • Array.fromAsync()

--lib esnext also now includes proposed methods such as Promise.allKeyed, Iterator.zip and Iterator.prototype.chunks.

Whether you can set --target es2026 depends on your runtime. Declaring a newer target while running on an older Node or browser means these methods may be missing at runtime, and TypeScript will not warn you. Check what your minimum supported runtime actually implements before bumping the target.

The new API, for tool authors

This is the biggest change for tooling. TypeScript 7.1 ships a new API organised into entry points rather than one monolithic module:

Entry point Purpose
typescript/sync Synchronous compiler client with compiler options, type-checker and program APIs
typescript/async Promise-based equivalent of the sync client
typescript/fs Request-scoped full and layered filesystems
typescript/ast Syntax tree node types and enums such as SyntaxKind and ScriptTarget
typescript/ast/is Node type guards
typescript/ast/factory create and immutable update functions

Two design details stand out. First, API and Program objects are disposable. The announcement explains that because TypeScript allocates memory that must live across the Go and JavaScript runtimes, you cannot leave cleanup to the garbage collector or you will leak on the Go side. Use the using keyword or call dispose methods yourself.

Second, snapshots. A snapshot is a version of all the projects and programs at a point in time, and you can derive a new one from a prior snapshot with the snapshot's update method. That models edits over time without rebuilding everything, which is exactly what editors and watch tools need.

The announcement's sample compiles explicit filenames and notes that, unlike tsc, it does not discover tsconfig.json or support --project. If you plan to build on the API, read that caveat first.

If you are following the broader TypeScript tooling story, we looked at a different approach in tsrs Is a Rust Port of TypeScript That Runs in the Browser. Try It in CI First, which compares itself against this beta.

Performance and what comes next

The announcement recalls that TypeScript 7 often achieved around 10x the performance of TypeScript 6. It says 7.1 brings a set of new optimizations to reduce memory pressure and speed up builds, among them improved program reuse and scheduling tsc -b projects by dependency depth. The post links charts comparing wall-clock time and memory use, but I would verify numbers on your own codebase, because monorepos behave very differently from small apps.

The team says the focus now is speed and stability, including feedback on the new features. A release candidate is expected in about a month, followed by a final release shortly after. So if you plan to adopt 7.1 on release day, now is the cheapest time to find the problems that affect you.

Should you try it?

Yes, on a branch. We haven't run the beta ourselves, and everything here is drawn from the team's announcement.

A sensible trial plan:

  1. Install the beta in a separate branch with npm install -D typescript@beta.
  2. Run your normal type check and compare the output with the stable version. New errors are information.
  3. If you import CSS, text or binary files, add attribute-aware declarations and see whether they replace your wildcard ones.
  4. If you maintain a build tool, editor plugin or linter, read the API section in full and try one small program through typescript/sync.
  5. Report problems to the TypeScript repository rather than working around them silently.

Troubleshooting

  • A declaration with attributes is ignored. Check that your --module setting is supported and that the declaration file is included in your project.
  • A source import errors. Confirm --module is esnext, nodenext or preserve and that you have the appropriate esnext option in --lib or --target.
  • Memory grows in a tool that uses the API. Make sure every API, Program and Snapshot is disposed, using using or an explicit dispose call.
  • A new lib method is undefined at runtime. Your runtime does not implement it yet, so lower the target or add a polyfill.

Frequently Asked Questions

How do I install TypeScript 7.1 Beta?

Run npm install -D typescript@beta, as given in the announcement.

Is--target es2026 stable?

Yes. TypeScript 7.1 supports es2026 as a stable --target and --lib option.

Do I need the new API if I only write applications?

No. It is aimed at people building tools on TypeScript's syntactic and semantic analyses.

Are source phase imports ready for JavaScript?

Not really. The team says you cannot do much with a source import of a JavaScript file yet, and many tools do not support it.

Originally published on Mango Developer.