Andrew Branch

Andrew Branch

@andrewbran.ch

Working on the TypeScript API at Microsoft.

1K followers112 following53 posts

Andrew Branch reposted

Some speed & memory improvements you'll see with TypeScript 7.1 Beta. We're hoping to land more before RC & stable.

TypeScript@typescriptlang.org

TypeScript 7.1 Beta is now available! Now with a preview API, content mapper support, new features, and some great optimizations. Give it a try and give us some feedback!

Andrew Branch reposted

Excited that TypeScript will finally support module types based on import attributes! Bundlers and frameworks can now provide accurate types for custom imports:

Andrew Branch reposted

Ember now has preliminary TS7 support ~ via the content-mappers feature that merged in TS last week Testers wanted! (requires TS Nightly)

Andrew Branch reposted

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

Now is a good time to start building with the API and sending feedback my way on GitHub. What are you still missing to be able to move your API-using projects to TS 7?

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

This simple example is running in the extension host, but you can imagine passing this connection to your own LSP server, serving additional completions or hovers in TS files by combining its own logic with type checker queries.

This LSP-connected API method is why everything goes through immutable snapshots. You can continue to work with immutable state for as long as you want, even if the user has moved files or continued typing.

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

So far, almost all of this code could be mistaken for the old TS 6 API. But under the hood, a lot of care has to go into pretty silly things like making sure when you get the same Type or Symbol twice, they have reference equality. That doesn't come for free anymore.

Let's do something totally different. Here's a VS Code extension, which gets a sidecar API connection to the TypeScript LSP that was already running. All the same APIs are available, and now you can inspect the projects the user has open in their editor. Here we're logging the exports of .ts files.

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

Now for some transformation. The new AST is a hybrid of these "remote nodes" backed by binary data and normal JavaScript objects. The client can encode the result into the same binary format so the server can run it through the emitter, in this case. Here's a (dumb) codemod to fix our error.

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

Every node materializes into an instance of the same class, all reading the same underlying buffer. The TS types lie and give each node a specialized type. Here, we see `kind` reading its value from an offset computed by the node's index in the flattened AST and the kind field's offset.

To demonstrate the laziness of file decoding, we can see that after recursively visiting one of the two statements in the file, 10 of the 20 nodes were actually materialized. (The timings here look slower than they should because the VFS is not yet production quality.)

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

View full thread

Slightly more interesting: let's navigate a source file and use the type checker on some stuff. This found the return type 'void' from `console.log` and the return type 'number' from `add`.

But how exactly does that work? The tsgo process encodes the AST in a compact binary format and sends it all over. The client's SourceFile type wraps the Uint8Array and exposes getters for every property you could want to access. Children and other properties are lazily decoded on first access.

If you’re not stalking TypeScript PRs, you might be surprised how much you can do with the API in nightlies (and even in 7.0 stable), so here’s a tiny demo that I think hits some of the highlights. 🧵

The API comes in sync and async flavors. You import from "unstable" for now, but it's not going to change architecturally before 7.1. Breaks will be mostly targeted renames/moves. You access programs through obtaining immutable snapshots. There will be more ways coming soon. More on this later.

Let’s start with something basic like getting diagnostics. Not too much to say about this. Each API call like this is communicating over STDIO with the tsgo process. We'll see some details in a minute.

Andrew Branch reposted

Andrew Branch reposted

Andrew Branch reposted

they coulda trained opus 5 to learn that typescript 7 is stable now because it simply refuses to believe oxlint with type checking enabled only takes 28ms to run

Andrew Branch reposted

I've been experimenting with having `ts-blank-space` use the (unstable) TypeScript-go JS API. At first it was ~60% slower than using the TS 6 API, but with a bit of investigation, a bug fix, and a small refactor to use different API calls it is now ~24% faster! Draft PR: github.com/bloomberg/ts...

Andrew Branch reposted

TypeScript 6.0 is now available! This release brings better type-checking for methods, new standard library features, new module features for Node.js, and more! But most important, this release brings us one step closer to the upcoming native-speed 7.0! devblogs.microsoft.com/typescript/a...

devblogs.microsoft.comAnnouncing TypeScript 6.0 - TypeScriptTypeScript 6.0 is now available! TypeScript 6 is a stepping-stone release, aligning with the upcoming native-speed 7.0 release.

Andrew Branch reposted

Andrew Branch reposted

Big news in this year's GitHub Octoverse report: TypeScript is now the most-used language on GitHub! We are thrilled and grateful to see the TypeScript and JavaScript community continue to grow and thrive. 🚀 Read up more at github.blog/news-insight...

github.blogOctoverse: A new developer joins GitHub every second as AI leads TypeScript to #1In this year’s Octoverse, we uncover how AI, agents, and typed languages are driving the biggest shifts in software development in more than a decade.

Andrew Branch reposted

Tonight will be one of the best nightlies of the TypeScript Native Preview ever. 1) @andrewbran.ch fully rewrote the language server infra into a snapshot model. No more data races. It's so cool 2) Sheetal added build mode (-b), and it's even _concurrent_ build mode. 10x+ on dt-tools, hot and cold

Andrew Branch reposted

Next week is gonna be a fun week Soon the scourge of baseUrl, paths, and typesRoot will be purged, replaced with "how about we actually use node_modules like everyone else" (thank you Andrew and Nathan for your efforts, and of course @zkochan.bsky.social and contributors for pnpm)

Andrew Branch reposted

We just released TypeScript 5.2 Beta! Check out - 'using' Declarations - Decorator Metadata - Easier Tuple Type Notation - Inline Variable Refactoring - Comma Completions in Objects and more! Try it today!

devblogs.microsoft.comAnnouncing TypeScript 5.2 Beta - TypeScriptToday we are excited to announce the availability of TypeScript 5.2 Beta. To get started using the beta, you can get it through NuGet, or through npm with the following command: npm install -D typescr...

You are up to date.