-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
TypeScript support in REPL #1158
Comments
Thanks for opening the issue @kitsonk. Compiler extensions were my questions to you. I'll take a look at EDIT: typo |
Just a couple of points on this based on some recent conversations:
|
No idea about the practicality of this suggestion, but could you have the best of both worlds by having the typescript support enabled through a flag? In other words, one REPL (e.g. loaded via |
Yeah, feels like we will need some sort of flag, because it is a bit heavyweight to have TS always on in the REPL. Technically, it shouldn't be too hard. |
Striping types should be easy enough - i kinda think v8 should be able to do it... I wonder if they would accept a patch to add an API for that... |
So, Babel does that. The TS team worked with Babel to ensure the lexer could "ignore" TS. So the logic is there and I suspect documented in some fashion. It is more than just types though, as there are some TypeScript syntax which has a functional emit and isn't erasable (which they avoid like the plague now), specifically |
It would be useful to be able to experiment in the repl and see type errors, supporting that would need more than just stripping types though. |
I just left this comment #3760 (comment)
|
Now that we have fairly frictionless access to swc and there are other reasons we might want to use swc in REPL to parse JavaScript, we could support TypeScript without type checking in the REPL. Thoughts @caspervonb? |
Preferably we would also add better completion if we're integrating TypeScript support but we can just do stripping as a first pass, I'll get back to this once I'm done with code coverage. |
While you're sorting this out, perhaps you might want to augment the banner for $ deno
Deno 1.9.0, repl js
exit using ctrl+d or close()
> If you opt for the $ deno repl --ts
Deno 1.9.0, repl ts
exit using ctrl+d or close()
> I think it's reasonable to want to "think this through" and to attend to other repl things first (e.g. better completion or tabs). But I was surprised when I added some simple typing to the deno repl (e.g. |
Took a stab at this recently, will be landing soon just need to wrap up some other patches. |
PR #998 provides a REPL for Deno, but only supports plain JavaScript. It needs to support TypeScript as well.
I was thinking about the approach and am writing up a couple ideas. ts-node provides a REPL and in looking at how they accomplish it seems like a reasonably logical approach to attempt with Deno. In order to support that, I think we need to do the following:
compiler.configure()
in [WIP] Configure compiler with tsconfig.json #1136 will likely be need as well to allow the REPL to change the configuration, which it will need to do. We might have to modify it so it actually allows some changes that we wouldn't normally allow.The reason it needs to work this way, is that in some cases, the TypeScript will output something higher up (like when it emits helpers) and those need to be evaled.
Things like imports and async are going to be complex, I would recommend we aim for an MVP and then figure out how to go from there.
cc: @bartlomieju
The text was updated successfully, but these errors were encountered: