Typescript support

Are there any plans to have Observable support Typescript in addition to JavaScript?

I work on a project that uses Typescript, and while Observable is great for testing and writing small code blocks, I find myself having to translate between JavaScript and Typescript a lot manually.

Thanks!
–jon

17 Likes

I would really love this one. Not using types feels unproductive and archaic.

4 Likes

Totally agree. Now we can mix all the power of JS with normal typed programming, fixing errors while programming not while debugging. And the debugging part is definitely the worst JS part, and which is more or less tolerable only when you’re using a JS IDE with debugging capabilities. On the contrary, when you program on TS, you spend 95% of time writing code, and not setting breakpoints and scattering dozens of console.log()'s.

1 Like

+1, would be great to gear something was happening on this. I would use observablehq a lot more if it supported TS.

2 Likes

You can set breakpoints in observable with “debugger” and jump out into chrome devtools. I actually think the debugging experience is better in Observable than in vscode, just coz you get to exploit the native programability of the environment. Note chrome devtools is the real idiomatic V8 integration point unlike vscode.

I do think Typescript could offer some increase options for intellisense, but the fact you can pause the program using dataflow manipulation and interrogate objects “live” means the main value prop of types are diminished in my opinion.

In my opinion, types improve development speed by making your program correct before you run it. It saves time wasted restarting programs just to hit silly bugs.

Observable improves development speed by allowing you to recode WHILE THE PROGRAM IS RUNNING, without wiping state. So it saves time but in a different way. You still make silly mistakes, but they do not cost you a full restart program loop to fix. Overall, I think Observable is the bigger timesaver.

If Typescript compilation slows down Observable iteration speed it would be a net loss. Overall I prefer Observable’s interleaved reactive and dynamic development loops over a rigid “write compile run” loop that compiled languages do.

If both can be done at the same time I guess that could be a win. Primarily I miss decent intellisense which is what some type annotations could provide

3 Likes

It would be a good first step if TS code just runs with the types stripped, so I can paste code here to test further without cleaning out the types some other way.

Going the whole way is going to be somewhat more difficult, and things that are easier (native jsx support, for example), seem more important.

Nonetheless, it would be awesome of course.

2 Likes

Indeed, some kind of typing would be tremendously useful and helpful. There is the added complexity of trying to keep up with each new version of TypeScript and this turning into an ever-expanding feature to implement and maintain but perhaps there’s some kind of balance you can strike that would provide value.

1 Like

Would it be possible for observable to implement the new TC39 Proposal GitHub - giltayar/proposal-types-as-comments: ECMAScript proposal for type syntax that is erased - Stage 0 Types as Comments? They could implement some type-checking without having to implement the entire tsc stack. I think this could provide value as it would allow for data type checking.

3 Likes

@reesericci yes this is closer to where I have landed on Typescript usage, just hints that give me squiggly and intellisense sometimes, but run as a background process, but otherwise compilation is not a precondition to running the Javascript program (because compilation ruins my workflow).

Related: Compiled code drops leading/following comments · Issue #359 · observablehq/feedback · GitHub