Hey everyone,
I’ve been thinking about TypeScript and npm lately. It seems like most big JavaScript runtimes (except browsers) can handle TypeScript now. So I’m wondering if we should start putting TypeScript code straight on npm instead of compiling to JavaScript first.
I’ve got a few questions about this:
- How does the TypeScript compiler deal with .ts files in node_modules?
- Can it find the right types without issues?
- Does it try to check types inside these files too?
- Is there a speed difference when parsing and checking types?
I’m curious to hear what you all think about this. It could change how we share and use packages. Has anyone tried this or know more about it? Thanks for any info!
I’ve actually experimented with publishing TypeScript directly to npm for a small library I maintain. While it worked for some users, it created unexpected issues for others. The biggest problem I encountered was with bundlers and build tools that weren’t configured to handle TypeScript out of the box.
One thing to consider is that even if runtimes support TypeScript, many deployment pipelines and CI/CD setups are still JavaScript-centric. This meant some of my users had to modify their build processes just to use my package, which wasn’t ideal.
In terms of performance, I did notice a slight increase in installation time for projects using my TypeScript package. It wasn’t major, but it was noticeable, especially for larger projects with many dependencies.
Ultimately, I reverted to publishing compiled JavaScript with declaration files. It’s not perfect, but it’s the most universally compatible approach I’ve found so far. The ecosystem might not be quite ready for direct TypeScript publishing, but it’s definitely moving in that direction.
While publishing TypeScript directly on npm is an intriguing concept, it’s important to consider the broader ecosystem. Many tools and build processes are still optimized for JavaScript. Additionally, not all developers are comfortable working with TypeScript, which could limit the adoption of your package. From my experience, maintaining separate .ts and .js files with declaration files (.d.ts) offers the best of both worlds. It allows TypeScript users to benefit from type information while ensuring compatibility for JavaScript projects. This approach has served my packages well, providing flexibility without compromising on type safety or performance.
Interesting idea! while ts support is growing, many projects still rely on js. publishing ts directly might cause compatibility issues. Plus, type-checking every dependency could slow down builds. maybe a hybrid approach where we publish both ts and js versions could work? just my thoughts tho