Speeding up the JavaScript ecosystem – Isolated Declarations
TypeScript's new isolated declaration feature in version 5.5 simplifies packaging, reduces type definition file creation time to less than a second, eliminates manual *.d.ts file creation, and enables easy code sharing without npm packaging complexities. This innovation enhances code-sharing efficiency and streamlines .d.ts file generation by requiring explicit return types for exported functions, revolutionizing the packaging and sharing process for developers.
Read original articleTypeScript's new isolated declaration feature in version 5.5 is transforming code sharing by simplifying packaging and reducing the time to create type definition files from minutes to less than a second. This feature eliminates the need to manually create *.d.ts files, making the publishing process faster and more efficient. By shipping TypeScript source code instead of .d.ts files, developers can now easily share code without the complexities of packaging for npm. Isolated declarations streamline the generation of .d.ts files by requiring explicit return types for exported functions, significantly reducing the time it takes to create them. This approach allows for on-the-fly generation of definition files when installing a package, simplifying the process of packaging and sharing code. The system has been successfully implemented in Deno and is compatible with various package managers, making it a game-changer for developers looking to streamline the code-sharing process.
Related
NPM and NodeJS should do more to make ES Modules easy to use
Boris Cherny discusses challenges with ES Modules in NodeJS and NPM, proposing solutions like simplifying file extensions, upgrading libraries, and phasing out CommonJS support in NodeJS to boost adoption rates.
AdonisJS
AdonisJS is a TypeScript-first web framework for Node.js, emphasizing type-safety, intellisense, and performance. It offers testing support, official packages like Lucid for SQL ORM, Auth for authentication, and a vibrant community.
Show HN: Synapse – TypeScript Toolchain for Cloud Apps
Synapse is a full-stack TypeScript toolchain with resource-driven programming, cloud-agnostic libraries, and fine-grained permissions. It includes a TypeScript compiler, fast package manager, and testing framework for local or AWS deployment. Installation instructions vary by OS. Leveraging TypeScript, esbuild, Node.js, Terraform, and AWS SDK. Detailed documentation on GitHub covers Custom Resources, Environments, Packages, and Tests, with a Quick Start guide available.
Exposition of Front End Build Systems
Frontend build systems are crucial in web development, involving transpilation, bundling, and minification steps. Tools like Babel and Webpack optimize code for performance and developer experience. Various bundlers like Webpack, Rollup, Parcel, esbuild, and Turbopack are compared for features and performance.
Declaratively build your APIs in TypeScript and Python
Metatype is a declarative API development platform focusing on creating reliable, modular components. It offers Typegraphs for composing APIs, Typegate for GraphQL/REST, and Meta CLI for live reloading. Users can access documentation and a quick start guide on the Metatype GitHub repository.
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 source code you have some catastrophic mistakes in your approach.
How would a project configure node and typescript to use a npm module that has exported .ts files?
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!
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.
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'll compile/inject the JS into your release artifacts on publish. Not sure if this feature requires isolated declarations though.
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 alleged pain points with some examples rather than just telling us how great this new feature is. I personally don't see how this changes my life at all, and I'm a full time JS/TS dev.
It'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 "contracts".
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.
There are unexpected things that you would never have suspected if you had not read the implementation.
(If you own code is in JS, that is)
Not… whatever this is.
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 vast majority of cases. It is the declarations analog of transpileOnly, which skips all type checks and simply strips Typescript's special syntax.
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's possible this is more relevant to users of that registry, but it's not clear why this is an issue when the registry itself is handling transpiling and declaration generation.
EDIT: To be clear, I think it's totally fine to publish your TS source in addition to your JS and d.ts outputs, just don't publish TS only packages, please.
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 implemented (in JS or TS)? It is not perfect but has worked for almost everyone. How would the author'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.
I write almost all my JavaScript projects with Typescript now (it's a bad sentence but you know what I mean), but I don't think we should ever make the life harder for those who only write in JavaScript.
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 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)
3) The isolatedDeclarations flag causes the TS compiler to trigger errors when any exports would require inference in order to generate .d.ts
4) Thus, the isolatedDeclarations flag can be used to guarantee compatibility with faster, simpler .d.ts generation using syntax-based transformation
5) A consequence of simpler .d.ts generation is that it can be trivially done in parallel, which can be helpful for large monorepos
Related
NPM and NodeJS should do more to make ES Modules easy to use
Boris Cherny discusses challenges with ES Modules in NodeJS and NPM, proposing solutions like simplifying file extensions, upgrading libraries, and phasing out CommonJS support in NodeJS to boost adoption rates.
AdonisJS
AdonisJS is a TypeScript-first web framework for Node.js, emphasizing type-safety, intellisense, and performance. It offers testing support, official packages like Lucid for SQL ORM, Auth for authentication, and a vibrant community.
Show HN: Synapse – TypeScript Toolchain for Cloud Apps
Synapse is a full-stack TypeScript toolchain with resource-driven programming, cloud-agnostic libraries, and fine-grained permissions. It includes a TypeScript compiler, fast package manager, and testing framework for local or AWS deployment. Installation instructions vary by OS. Leveraging TypeScript, esbuild, Node.js, Terraform, and AWS SDK. Detailed documentation on GitHub covers Custom Resources, Environments, Packages, and Tests, with a Quick Start guide available.
Exposition of Front End Build Systems
Frontend build systems are crucial in web development, involving transpilation, bundling, and minification steps. Tools like Babel and Webpack optimize code for performance and developer experience. Various bundlers like Webpack, Rollup, Parcel, esbuild, and Turbopack are compared for features and performance.
Declaratively build your APIs in TypeScript and Python
Metatype is a declarative API development platform focusing on creating reliable, modular components. It offers Typegraphs for composing APIs, Typegate for GraphQL/REST, and Meta CLI for live reloading. Users can access documentation and a quick start guide on the Metatype GitHub repository.