Earlier quoted context omitted.
Yes, I recommend shipping TS source alongside compiled JS+d.ts even if you don't support a TS native environment, because you then have the potential of a source mapped debugging experience within that library (though currently doing that is a bit painful in some debuggers).
That can be nice, but do keep in mind that shipping more files leads to a larger tarball downloaded from npm.
Speeding up the JavaScript ecosystem – Isolated Declarations
41–50 of 57 posts
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#42This article is kind of a messy read, isolated declarations feels like it's being used as a mcguffin to advertise the jsr registry. Both may be neat things on their own, but I feel the connection is a bit misleading. Isolated declarations should allow parallelization and faster type checking with tooling that supports it. This shouldn't be changing your build/release process or what you export in your package.json. I…
For Node users the isolated declaration feature won't do much other than speed up the creation of the .d.ts files a little. For runtimes that can run TS natively like Deno (disclaimer: I work for Deno) the benefit is much more apparent as you always want the original TS sources, but can generate .d.ts files on the fly for faster type checking.
EDIT: Formatting
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#43whilst 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…
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#44...wait. Is the entire article based on the assumption that everyone has Typescript installed in every project? Otherwise, how would publish Typescript files work at all? > We only ever ship build artifacts, the compiled JS and the relevant .d.ts files in a package. Isn't this because anyone, regardless of whether they have use the project in JS or TS, can import the library without caring out how the library code is…
I think most bundlers can handle TS nowadays so you don't actually need tsc.
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#45whilst 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…
I think they are referring to the manual creation of type definitions. As they mention it in the article.
There are cases where folks write them by hand, but that's not what I had in mind when writing the article. I've rephrased that part a bit to hopefully make it less confusing.
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#46This doesn't really seem to address my most common packaging pain points in the JS/TS ecosystem (which is the inability to easily use ESM in legacy commonjs applications) but maybe I'm just working in the wrong area? I think the author seriously exaggerates the difficulty of creating type declaration files. It's literally one boolean setting in your tsconfig. I wish they would have given more time to proving the alle…
The article suggests that you ship typescript so the app would compile down to esm or cjs. Node 22 has an experimental flag that supports requiring esm as long as there's no top-level await
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#47The site's down for me, here's an Internet Archive link: https://web.archive.org/web/20240706220437/https://marvinh.d... I've really enjoyed this author's series on optimization techniques explored through non-trivial yet still small case studies, the other articles linked near the top are all worth checking out too!
Happy to hear that you like the series!
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#48From what I understand, the author is persuading library authors to stop compiling TS->JS, and instead ship your TS files to the users over npm. I like the idea of it, but will it actually work in practice? What if some dependency only compiles with some version of tsc? What if it needs different tsconfig-s?
In Deno (disclaimer: I work for Deno), which supports running TS natively, packaging outside of npm has always worked by shipping the TS files directly. Transpiling them down to JS files is only something you ever had to do when publishing on npm.
So far the problem that a dependency only compiles with a certain version of tsc hasn't popped up since Deno was launched. But that may have been because Deno always ships with latest TS and Deno users don't hesitate to update as we haven't done any breaking changes so far.
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#49I feel like the point is skipped in the post: if you ship TS sources, it means you need the TS compiler on the installed side, right? And specifically the right TS version for each installed package... which in some cases may mean conflicting requirements? (If you own code is in JS, that is)
Re: Speeding up the JavaScript ecosystem – Isolated Declarations
#50Please do not start publishing raw Typescript into the NPM registry thinking that all the reasons we have not done that in the past do not continue to apply. I shouldn't have to say this, but at least 27 people upvoted this article, so here we are. isolatedDeclarations is most useful for large codebases and other situations where performing a full Typescript compilation is prohibitively expensive. This is not the vas…
I mainly work with Deno which can run TS files natively (disclaimer: I'm employed by them). This changes the parameters a little as all registries for Deno could always ships the TS sources directly. But when publishing to npm you always have to publish the JS sources to work with runtimes like Node that don't support running TS natively.