TypeScript in Go? Microsoft's New Project & What It Means For Developers
Microsoft is working on something big: a native port of TypeScript to Go. This project, dubbed typescript-go, has generated a lot of buzz. But what does it mean for developers, and what can you do with it right now?
This article dives deep into the project, its goals, current status, and how you can start experimenting with it. We'll also cover the potential benefits of running TypeScript on Go.
What is TypeScript-Go? A Native Port Explained
TypeScript-Go is a Microsoft-led project aimed at creating a native implementation of the TypeScript language using the Go programming language. This means the TypeScript compiler and language service are being rewritten in Go, instead of relying on the traditional JavaScript-based implementation.
Why Port TypeScript to Go? Potential Advantages
Why undertake such a significant project? There are several potential advantages to running TypeScript on Go:
- Performance Boost: Go is known for its speed and efficiency. A Go-based TypeScript compiler could lead to faster build times and better performance.
- Reduced Dependencies: A native Go implementation could reduce the dependency on Node.js and its ecosystem.
- Cross-Platform Compatibility: Go's excellent cross-platform support could make it easier to run TypeScript in various environments.
Current Status: What Works, What Doesn't?
The TypeScript-Go project is under active development and not yet feature-complete. Here's a breakdown of what's working and what's still in progress:
- Program Creation: Done. The same files and module resolutions as TypeScript 5.8 are supported.
- Parsing/Scanning: Done. Expect the same syntax errors as TS5.8
- Commandline and tsconfig.json Parsing: Mostly done.
- Type Resolution & Checking: Done. Get the same types and errors as TS5.8.
- Emit (JS Output): In Progress.
target: esnext
is well-supported. - Watch Mode: Prototype. Watches files and rebuilds, but lacks incremental rechecking.
- Language Service (LSP): Prototype only, with minimal functionality (errors, hover, go to def).
Not Ready: JavaScript-specific inference, JSX, Declaration emit, Build mode/project references, Incremental build, and API.
Getting Started: How to Build and Run TypeScript-Go
Interested in trying out TypeScript-Go? Here's how to get started:
-
Prerequisites:
- Go 1.24 or higher
- Node.js with npm
hereby
(install withnpm install -g hereby
)
-
Clone the Repository: Use the following command to clone the repository with submodules:
If you've already cloned, initialize the submodule:
-
Install Dependencies: Run
npm ci
to install the necessary dependencies. -
Build the Project: Use
hereby build
to verify that the project builds successfully.
Running tsgo
: Your TypeScript Compiler
After building, you can run built/local/tsgo
, which mimics tsc
. Use tsgo tsc [flags]
for behavior similar to the regular TypeScript compiler. This typescript-go compiler allows you to experiment with the Go port.
LSP Prototype: Try the Language Service
To test the Language Service Protocol (LSP) prototype:
- Open the repo in VS Code (
code .
). - Copy
.vscode/launch.template.json
to.vscode/launch.json
. - Press
F5
(or useDebug: Start Debugging
).
This will launch a VS Code instance using the Corsa LS backend. "typescript-go" should appear in the Output pane.
Contributing to the Project
The TypeScript-Go project welcomes contributions! Before contributing, ensure you agree to the Contributor License Agreement (CLA). Check the Microsoft Open Source Code of Conduct for guidelines.
Meet the Contributors
A dedicated team is working on this project. Here are a few of the core contributors:
plus many other contributors.
The Future of TypeScript-Go
The long-term goal is to merge TypeScript-Go into the main microsoft/TypeScript
repository. The TypeScript-Go repository and issue tracker will eventually be closed.
This project represents a significant step forward for TypeScript. By leveraging the performance and efficiency of Go, Microsoft aims to improve the developer experience and expand the reach of TypeScript. Although it's still under development, TypeScript-Go has the potential to revolutionize the way we build and run TypeScript applications. Keep an eye on this project as it evolves! Understanding the nuance of the current typescript-go implementation helps prepare developers for the future of the typescript-go project.
The ongoing development of TypeScript can also impact different languages. Learning how javascript or even Go development affect the typescript-go project will also be very relevant for developers.