TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Speeding up the JavaScript ecosystem – Isolated Declarations

45 pointsby realshadow11 months ago

13 comments

austin-cheney11 months ago
<i>whilst reducing the time to create type definition files from minutes, sometimes even hours, down to less than a second.</i><p>WTF. What kind of project would take long to compile from TS? Windows 11 (if it were TS)?<p>I had a long time personal project that was several megs of code with several hundred types&#x2F;interfaces. It took 13 seconds to compile. If your application takes hours to compile and is less than a petabyte of source code you have some catastrophic mistakes in your approach.
评论 #40895668 未加载
评论 #40895340 未加载
评论 #40894432 未加载
seniorsassycat11 months ago
The blog doesn&#x27;t explain how to take advantage of isolated modules without using JSR, or how JSR transforms published packages.<p>How would a project configure node and typescript to use a npm module that has exported .ts files?
评论 #40894496 未加载
matthberg11 months ago
The site&#x27;s down for me, here&#x27;s an Internet Archive link:<p><a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20240706220437&#x2F;https:&#x2F;&#x2F;marvinh.dev&#x2F;blog&#x2F;speeding-up-javascript-ecosystem-part-10&#x2F;" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20240706220437&#x2F;https:&#x2F;&#x2F;marvinh.d...</a><p>I&#x27;ve really enjoyed this author&#x27;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!
评论 #40895698 未加载
_jackwink11 months ago
This article is kind of a messy read, isolated declarations feels like it&#x27;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.<p>Isolated declarations should allow parallelization and faster type checking with tooling that supports it. This shouldn&#x27;t be changing your build&#x2F;release process or what you export in your package.json.<p>If you also happen to use the jsr registry to publish your package, it sounds like you can update your package.json to export TS files and they&#x27;ll compile&#x2F;inject the JS into your release artifacts on publish. Not sure if this feature requires isolated declarations though.
评论 #40895648 未加载
ericyd11 months ago
This doesn&#x27;t really seem to address my most common packaging pain points in the JS&#x2F;TS ecosystem (which is the inability to easily use ESM in legacy commonjs applications) but maybe I&#x27;m just working in the wrong area?<p>I think the author seriously exaggerates the difficulty of creating type declaration files. It&#x27;s literally one boolean setting in your tsconfig. I wish they would have given more time to proving the alleged pain points with some examples rather than just telling us how great this new feature is. I personally don&#x27;t see how this changes my life at all, and I&#x27;m a full time JS&#x2F;TS dev.
评论 #40894972 未加载
pzmarzly11 months ago
From what I understand, the author is persuading library authors to stop compiling TS-&gt;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?
评论 #40894839 未加载
评论 #40895712 未加载
29athrowaway11 months ago
JavaScript runtimes are full of optimizations that execute conditionally on specific scenarios. If you don&#x27;t follow the rewarding path of optimization you then go to the deeply unhappy path of deoptimization.<p>It&#x27;s easy to get started with JavaScript, but to squeeze every bit of performance in JavaScript will quickly get you into a very complex topics that are not documented and change may change from version to version as they are often not &quot;contracts&quot;.<p>The only way to learn those obscure topics is by reading the source code for your JavaScript implementation, their bug tracker, etc. This means if you have not been reading C++ or executed a non-JS profiler to make your JS faster then you probably have not gone far enough.<p>There are unexpected things that you would never have suspected if you had not read the implementation.
viraptor11 months ago
I 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?<p>(If you own code is in JS, that is)
评论 #40895719 未加载
评论 #40893983 未加载
评论 #40895415 未加载
tlarkworthy11 months ago
I don&#x27;t know what an isolated declaration is. Do we write TS source differently?
stevenpetryk11 months ago
I believe the intention behind isolatedModules is to make compilation faster by forcing you to define types that require no inference from other files (thus, being isolated).<p>Not… whatever this is.
rezonant11 months ago
<i>Please</i> 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.<p>I shouldn&#x27;t have to say this, but at least 27 people upvoted this article, so here we are.<p>isolatedDeclarations is most useful for large codebases and other situations where performing a full Typescript compilation is prohibitively expensive. This is not the vast majority of cases. It is the declarations analog of transpileOnly, which skips all type checks and simply strips Typescript&#x27;s special syntax.<p>The author seems to assume use of JSR, which is an alternative to the NPM registry which automatically compiles Typescript. Not being terribly familiar with it, it&#x27;s possible this is more relevant to users of that registry, but it&#x27;s not clear why this is an issue when the registry itself is handling transpiling and declaration generation.<p>EDIT: To be clear, I think it&#x27;s totally fine to publish your TS source <i>in addition</i> to your JS and d.ts outputs, just don&#x27;t publish TS only packages, please.
评论 #40895731 未加载
评论 #40895047 未加载
评论 #40894987 未加载
rty3211 months ago
...wait.<p>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?<p>&gt; We only ever ship build artifacts, the compiled JS and the relevant .d.ts files in a package.<p>Isn&#x27;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 implemented (in JS or TS)? It is not perfect but has worked for almost everyone. How would the author&#x27;s project layout help people who only ever write code in JavaScript and never installed the Typescript package? Does Typescript have to be a dev dependency of any project that has an upstream package written in Typescript? That seems a bad idea.<p>I write almost all my JavaScript projects with Typescript now (it&#x27;s a bad sentence but you know what I mean), but I don&#x27;t think we should ever make the life harder for those who only write in JavaScript.
评论 #40895398 未加载
rtsao11 months ago
I&#x27;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).<p>I&#x27;ll try my best to break it down succinctly:<p>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)<p>2) However, if types were to be fully explicit, then .d.ts generation could be performed without a full type checker (i.e. by a faster compiler via mere syntax transformation)<p>3) The isolatedDeclarations flag causes the TS compiler to trigger errors when any exports would require inference in order to generate .d.ts<p>4) Thus, the isolatedDeclarations flag can be used to guarantee compatibility with faster, simpler .d.ts generation using syntax-based transformation<p>5) A consequence of simpler .d.ts generation is that it can be trivially done in parallel, which can be helpful for large monorepos
评论 #40895751 未加载
评论 #40894857 未加载
评论 #40893855 未加载