Skip to content

Conversation

@NatoBoram
Copy link
Owner

@NatoBoram NatoBoram commented Aug 11, 2024

An attempt at using TypeScript without a compilation process

📝 Description

Node.js added --experimental-strip-types in v22.6.0, which allows it to run TypeScript files without a compilation process.

Avoiding the build step to run Node.js TypeScript applications could be very useful for all projects running directly with Node, like Express applications. It can drastically simplify the deployment process, particularly with Cloud Functions.

However, published CLI apps might not work if --experimental-strip-types cannot be passed to files listed in bin. Additionally, published libraries will not work on the browser unless a bundler is used, which is already expected from modern front-end development.

I am expecting --experimental-strip-types to be the default behaviour in the release of Node 23.

Overall, it seems like a TypeScript-only package would cause a very minimal amount of friction in the ecosystem due to browsers always being late to the party.

  • Enable allowImportingTsExtensions and noEmit in tsconfig.json
  • Change imports for .ts
  • Export directly from src
  • Set engines to node >=22.6
  • Updated GitHub Workflows to node-version: >= 22.6
  • Uninstall tsx from the devDependencies

📓 References

Type stripping in dependencies

To discourage package authors from publishing packages written in TypeScript, Node.js will by default refuse to handle TypeScript files inside folders under a node_modules path.

@NatoBoram NatoBoram self-assigned this Aug 11, 2024
@NatoBoram NatoBoram changed the title ⚗️ TypeScript-only package with Node 23 ⚗️ TypeScript-only package with Node 22.6 Aug 11, 2024
@NatoBoram
Copy link
Owner Author

TypeScript-only packages are explicitly disallowed by NPMJS, but they are encouraged on JSR. It might be time to consider changing default package registry for publishing.

However, this repo's goal is to remain compatible with Node's defaults - for example, I'm using pnpm but one could still downgrade to npm.

@NatoBoram NatoBoram closed this Sep 23, 2024
@NatoBoram NatoBoram deleted the feature/node-23 branch May 28, 2025 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants