Live data from Hacker News

Speeding up the JavaScript ecosystem – Isolated Declarations

marvinh.dev

51–57 of 57 posts

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#51
post #3

I've heard of `isolatedDeclarations` in TS 5.5, but this post left me with more questions than answers because it conflates so many distinct things (TS 5.5, Deno, JSR). I'll try my best to break it down succinctly: 1) Historically, .d.ts generation is slow because it requires the full TypeScript type checker in order to correctly handle all cases (e.g. exported functions with inferred return types) 2) However, if typ…

Author here. That's good feedback. Looks like that part of my article is a bit confusing and I've updated the phrasing a little to hopefully make it less so.

You're spot on with all of your points. The isolated declarations feature forces your code to be written in a way that creating the .d.ts files is a mere exercise of stripping syntax and can be done easily without invoking the tsc compiler.

For runtimes like Deno which support running TS natively (disclaimer: I work for Deno) you never had to care about creating .d.ts files when publishing your package to any of the Deno registries: previously /x, now JSR. In the background though we've always tried to feed the tsc compiler in Deno something like .d.ts files though as it's quicker for type checking purposes.

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#53
post #8

Earlier quoted context omitted.

I think they are referring to the manual creation of type definitions. As they mention it in the article.

Author here. Unfortunately, I think worded that a bit confusingly in the article. I'm used to working with runtimes that run TS natively and didn't have to care about .d.ts files myself for a long time. From that perspective creating them by running the tsc compiler feels like a manual step for me. There are cases where folks write them by hand, but that's not what I had in mind when writing the article. I've rephras…

Thanks for the clarification.

The fact that there are developers out there that are willing to accept hour long compile times from the typescript compiler is disgusting. I’ve seen slow recursive types here and there, but you can analyze your slow types using tsc and fix them yourself.

I hope that slow typescript compiling is a niche issue for massively large/complex codebases and not a common problem.

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#54
post #32

Earlier quoted context omitted.

I write TypeScript projects in TypeScript from the start. If I have an existing JS project that needs to port to TypeScript then I will rewrite it entirely in TypeScript. Yes, that takes some small amount of time, but it’s never a complete rewrite. It’s mostly just minor syntax updates as the actual runtime should remain the same as validated by test automation. I type everything I declare whether a primitive or not.…

But why would any of that need to be done manually in a .d.ts file? You can just write your type definitions in ts files

Types are meta data for the compiler. They are not code that is compiled to JavaScript, so I isolate my type definitions to d.ts files. That is the only reason I have d.ts files at all.

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#55
post #35

whilst reducing the time to create type definition files from minutes, sometimes even hours, down to less than a second. WTF. What kind of project would take long to compile from TS? Windows 11 (if it were TS)? I had a long time personal project that was several megs of code with several hundred types/interfaces. It took 13 seconds to compile. If your application takes hours to compile and is less than a petabyte of…

You seem confused about what .d.ts files are. They are type definitions to make using JavaScript code in typescript nicer. They're not regular typescript code. Just think if you had to take a big JavaScript library, say the size and level of dynamism of jQuery, and manually write annotations for it yourself. It would indeed take you hours to cover everything.

I am aware. I only use d.ts files to store statements starting with keywords type or interface.

BTW, jQuery is pretty small. With good lint rules you could probably manually type everything without missing anything in less time than you think. Whatever time is spent doing this manually apparently is worth the cost savings comparing to long compile times if takes more than a few seconds. You only need to write the types once and then again on major refactors. If your builds just take seconds you can run them dozens of times a day. If your compile time is hours then whatever automation you imposed to write your types or d.ts files for you is entirely self-defeating as its costing you dramatically more than just doing it manually one time.

When you have a large project types are written as the code they describe are written, so its little more effort than typing on the keyboard in a separate file.

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#56
post #39

Earlier quoted context omitted.

I write all my d.ts files manually. Maybe that’s the problem: people don’t know how to write TS, expect some software to do it for them, and then end up waiting hours on a build that should take 10 seconds.

Maybe if writing .d.ts-es by hand was a proper way to write TS, people would know about that from the docs. Don’t sell your fetishes as some sort of a common knowledge please, it doesn’t help anyone.

Writing types yourself may or may not be the best approach. Everybody is entitled to their opinions. However, builds that take more than 30 seconds (and that is extremely forgiving) is ridiculously wrong.

So, my very best recommendation is to turn that frown upside down and measure things. This is called total cost of ownership (TOS). If the cost of manually writing types is less than the total cost of running builds in a week you then it is absolutely the most correct approach.

https://en.wikipedia.org/wiki/Total_cost_of_ownership

As far as fetishes go I try to avoid logical fallacies like you recommended for me: https://en.wikipedia.org/wiki/Argumentum_ad_populum

Re: Speeding up the JavaScript ecosystem – Isolated Declarations

#57
post #32

Earlier quoted context omitted.

But why would any of that need to be done manually in a .d.ts file? You can just write your type definitions in ts files

Types are meta data for the compiler. They are not code that is compiled to JavaScript, so I isolate my type definitions to d.ts files. That is the only reason I have d.ts files at all.

Types are also documentation for the developers reading and editing the code.
Post reply on HN