-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native TypeScript support #3703
Comments
An experimental integration of |
Intercepting here some potential future problems that we may encounter during the integration. k6pack should run https://github.com/grafana/k6-ci as we are doing on other extensions. Maybe only part of it does make sense, a good start is the linter. |
FYI: the grafana bench project is using the k6pack to pre-compile the type script tests before invoking k6. We didn't use the |
I implemented my first integration idea. No test code written yet, I'd like to justify with core team is it the right way to integrate or not... Basically: I introduced a new compatibility mode: "enhanced". Using this compatibility mode activates k6pack (esbuild) bundling of the test script. The bundling happen in test load phase so the archive will be contains the bundled script... @codebien could you take a look it plz... |
This is not an exhaustive list of things, I just decided to post them as this already is very delayed response, for which I am sorry 🙇 General notes on typescript supportesbuild does not support typescript checking it "just" discards types to make it javascript compatible. This means that either:
IMO this makes the use case a lot smaller. And probably less relevant as:
So it seems likely users will either have to run tsc either way or they just need their IDE to be setup correctly. Still no zero benefits though. But I will argue that the wording of "native typescript support" is not correct:
From the list of caveats in the docs there seem to be other things that we might need to look into:
It will be nice to have some idea how fully supporting is esbuild of typescript? Are there some holes that aren't supported? I am also not certain how much "steam" typescript have, given that there have been some "thought-leaders" arguing against it and the tc39 proposal seemingly going nowhere. It still does seem to be the de facto winner between it and jsdoc and I don't think anyone remember flow at this point. More notes on the current implementationThe compatibility mode is niceI do like this approach especially as it isn't the default. I will probably want it to have "experimental-" prefix for a while though. It produces as single final fileInstead of actually compiling it per file. As the docs shows esbuild actually does this per file, so this seems like the better approach. The current problem is that after you use this option you get one final packed file that prevents k6 from knowing where the original file is when it actually executes. Which does break import "./a/a.js"
export default () => { } a/a.js: open("./test"); a/test:
Adding more javascript support through esbuildI heard people wanting this, but unfortunately while this might work for some cases it has two caveats:
|
@mstoykov , Thank you for your comments. I have transformed the use of esbuild as discussed, now it runs per module. In practice, it runs instead of Babel in the "enhanced" compatibility mode. I also ran the tc39 tests. I adjusted the running of the tc39 tests a bit to be able to use more compatibility modes. I have prepared a draft PR, I would appreciate it if you could review it. PR: #3738 |
I don't think we should guide our roadmap based on "thought-leaders" as they have their own agenda of keeping themselves "relevant" by continuously introducing a new "next big thing". What I think should matter is the adoption in k6 user base or testing community in general. In That regard, my anecdotical evidence is that TS is widely used. It would be interesting to have more information about how much the k6 users demand ts. Having an initial implementation that makes this possible (with the limitations you mention) maybe will allow us to uncover a latent demand. |
Feature Description
TypeScript has become increasingly popular for its strong typing system, which enhances code quality and reliability—key aspects in performance testing scenarios. Currently, k6 does not support TypeScript out-of-the-box, requiring users to rely on external tools to transpile TypeScript code into JavaScript before it can be run by the tool. This additional step not only complicates the setup process but also impacts the overall developer experience, especially for those who primarily work with TypeScript. This setup also discourages TypeScript developers from adopting k6, despite its powerful testing capabilities.
Suggested Solution (optional)
To address the current gap, I suggest integrating k6pack, a solution based on esbuild, into the core functionality of k6. esbuild is a TypeScript transpiler and bundler written in Go, which aligns well with k6’s Go-based architecture. The integration would involve automatically invoking k6pack during the k6 launch process to transpile TypeScript scripts into executable JavaScript.
This integration can be structured as follows:
Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered: