What is the API story for this new codebase? #455
Replies: 14 comments 32 replies
-
What are your IPC plans for WebAssembly in the browser? |
Beta Was this translation helpful? Give feedback.
-
Have you considered WASM as a solution to providing a cross-language API? I haven't used it for this purpose, but it seems like there could be a good match in requirements. WASM modules can pass typed data to one another, call one another's functions, etc. |
Beta Was this translation helpful? Give feedback.
-
How's the story for TypeScript plugin developers and people integrating with the language service? More specifically, will method patching still work? The official way to create a plugin is to patch methods. And across such use cases there are probably dozens of cases where people reach into TypeScript semi-private internals to patch other methods (so that things can be intercepted for example) - will that also still work? If not, how do you envisage plugin authors to migrate away from doing that? |
Beta Was this translation helpful? Give feedback.
-
I've used the tsc api for various codegen purposes, will you be exposing an API to walk/visit the AST tree as was available in the js tsc api? |
Beta Was this translation helpful? Give feedback.
-
Will error reporting change? For a long time, TS errors have been a heated topic and there have been efforts by the community (https://github.com/yoavbls/pretty-ts-errors) to make it a little better. Will solutions like Pretty TS still work in the new world? |
Beta Was this translation helpful? Give feedback.
-
Are there plans about instead of IPC there would be something like FFI? |
Beta Was this translation helpful? Give feedback.
-
Not a question, but an observation: Right now, lots of tools which depend on types (TypeScript Eslint, Typia, etc) run their own Lexer, parser and type checker. It is not uncommon to have separate type checkers running in the ESLint process, in a development server and in the TypeScript language service. This leads to doing a lot of work twice or more and can also lead to inconsistencies if the tooling does some weird stuff. With an IPC layer it could become very feasible to have all of these hook into one tsgo process and have one source of truth for type information, meaning that the development experience when using these kinds of tools could get a lot smoother. Maybe this is something that can be considered when designing the IPC layer - i.e. to allow having one tsgo "server" and multiple clients consuming it's API. |
Beta Was this translation helpful? Give feedback.
-
Is now maybe the time to also re-consider adopting semver from the API perspective? I could usually care less about breaking changes from the language and type checking perspective, but I would love it if from the tooling perspective we could get some sort of guarantees of what versions of the typescript api are supported and compatible. I will acknowledge that in the past this was a harder sell because of the nature of javascript and how the entire AST and compiler internals are essentially all public api. As a result, any change or internal refactoring could therefore be considered a breaking change, and thus nothing was. If the team is being more intentional about what is exposed across the API boundary, it can be more reasonable. My ideal would be something like: Note: changes to the language that add new features may change the resulting AST that is returned from the API. This should not be considered a breaking change to the API, but maybe things like removing documented properties from existing nodes, might be? That way, tooling providers can set their expectations of supported typescript releases based on the |
Beta Was this translation helpful? Give feedback.
-
Hey there, I'm developing an experimental Node.js binding here: https://github.com/Brooooooklyn/typescript-go-napi/tree/main/rust The basic idea is to compile typescript-go into a static link library, and then wrap it into a JavaScript API in Rust using NAPI-RS. I have now completed two basic APIs, among which transform is like this: import { transform } from '@typescript-go/api'
transform('const a: number = 1;', '/absolute/path/a.ts')
// 'const a = 1;\n' |
Beta Was this translation helpful? Give feedback.
-
How future-proof is this module? Webdriverio badly wanted to provide a sync API for writing tests, and relied on |
Beta Was this translation helpful? Give feedback.
-
Adding my two cents here, if API is not possible for major languages (mainly JS and probably Rust for SWC/OXC), a static type info snapshot can also be helpful. (though it is not possible to do transformation) Related issues #504 |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to use tsc-go as a library from Go and hook into it that way? As opposed to plugins and IPC etc? |
Beta Was this translation helpful? Give feedback.
-
The TypeDoc project uses TypeScript compiler APIs (including watch-related APIs) to generate documentation from source projects (via JSDoc as well as TypeScript type info) and to respond to changes in the code base and non-code documentation files. Will the same or substantially similar watch APIs be available from JS? (i.e. including the ability to add arbitrary watches as well as incremental-compile-on-change) |
Beta Was this translation helpful? Give feedback.
-
The beginnings of the IPC API are now in a PR at #711. |
Beta Was this translation helpful? Give feedback.
-
How will the API work? Will developers have a canonical JavaScript-based API for integrating with this new version of TypeScript?
While we are porting most of the existing TypeScript compiler and language service, that does not necessarily mean that all APIs will be ported over. Because of the challenges between language runtime interoperability, API consumers will typically not communicate within the same process. Instead, we expect our API to leverage a message-passing scheme, typically over an IPC layer. Because this sort of bridging is not "free", exposing all functionality will be impractical. We expect to have a more curated API that is informed by critical use-cases (e.g. linting, transforms, resolution behavior, language service embedding, etc.).
We knew that providing a solid API would be a big challenge, so as soon as we started exploring the TypeScript port, we investigated the possibilities here. Beyond how capable the API would be, we asked ourselves whether the sorts of use-cases would be constrained by the performance of IPC solutions. More specifically, even if we could come up with a set of APIs that did what users wanted, would the throughput of requests be a limiting factor? Would the new TypeScript be fast enough to offset the cost of serialization and data transfer? Would the chattiness of API usage overwhelm the wins of having a much faster compiler?
We've become increasingly confident and optimistic in answers around the IPC performance. @zkat has built a Node native module to use synchronous communication over standard I/O between external processes. Building on that, @andrewbranch has experimented with exposing an API server entrypoint to our compiler, along with a JavaScript client that "speaks" to the server over that communication layer. What we've found is fairly promising - while IPC overhead is not entirely negligible, it is small enough. We also can imagine opportunities to optimize, use other underlying IPC strategies, and provide batch-style APIs to minimize call overhead.
As our experiments solidify, we will post more concrete details on our plans, and what the API will look like.
Beta Was this translation helpful? Give feedback.
All reactions