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.

TypeScript NPM Packages Done Right

102 pointsby chatgidipiover 1 year ago

14 comments

GrygrFlzrover 1 year ago
<i>Also, the default target configuration is &quot;es2016,&quot; and modern browsers only support up to &quot;es2015.&quot;</i><p>I had to recheck this was indeed an article from 2023, because this part surprised me greatly. To my understanding, es2016 only added Array.prototype.includes, the exponentiation operator (**), and preventing generator functions from being constructed. Even the slowest adopters already had these in 2017. Is the author assuming IE11 support?
评论 #37631716 未加载
评论 #37632592 未加载
评论 #37631284 未加载
mckravchykover 1 year ago
Is there a reason why npm packages should not target the highest possible target that an LTS Node.js supports? On the front-end those that need lower targets will run their own transpiling anyway to whatever target they want. I&#x27;m about to release a few simple npm packages and I&#x27;m considering ES2017 as the target (since it has the last major feature - async &#x2F; await). I&#x27;m guessing it&#x27;s just that the end-user of the library would need to be aware of the polyfills that need to be supplied. I have asked a question [0] about it a while back but it did not get any responses.<p>To clarify - the goal is if you have a project that uses ES7, why would you want to use a package written in ES2020 that is transpiled to, i.e. ES2016 using non-native async &#x2F; await.<p>[0] <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;76558023&#x2F;whts-the-ideal-es-target-for-an-npm-package" rel="nofollow noreferrer">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;76558023&#x2F;whts-the-ideal-...</a>
评论 #37635661 未加载
franky47over 1 year ago
`tsc` is extremely slow to transpile TypeScript sources into JavaScript. It&#x27;s invaluable for typechecking, but for transpilation there are much better solutions like SWC or tsup [1] (which nicely wraps esbuild and Rollup).<p>[1] <a href="https:&#x2F;&#x2F;tsup.egoist.dev&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;tsup.egoist.dev&#x2F;</a>
评论 #37632043 未加载
评论 #37632117 未加载
评论 #37633878 未加载
skybrianover 1 year ago
I&#x27;m wondering if there&#x27;s a tool that converts TypeScript into JavaScript that has JsDoc type annotations and preserves API docs? Then you wouldn&#x27;t need to include anything else. Let the application minify if they choose.
评论 #37634650 未加载
评论 #37636211 未加载
评论 #37634138 未加载
tritiyover 1 year ago
While the article is technically correct it avoids the most common issue with &#x27;pure&#x27; typescript libraries in that you still need a bundler if you have multiple .ts files. Once you enter that territory you realize how much more complex everything becomes.
评论 #37632937 未加载
评论 #37634197 未加载
gdprrrrover 1 year ago
See also <a href="https:&#x2F;&#x2F;publint.dev&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;publint.dev&#x2F;</a>
评论 #37631917 未加载
评论 #37637289 未加载
edwinjmover 1 year ago
&quot;module&quot;: &quot;commonjs&quot;,<p>Nope.
评论 #37632201 未加载
evnixover 1 year ago
I understand the whole CommonJS Vs imports situation.<p>I have been that vocal minority that keeps complaining about CommonJS support to library authors. But I have given it up for the greater good.<p>we have a standard now, CommonJS needs to go, why keep pushing non standard stuff in a 2023 article.
评论 #37632800 未加载
评论 #37631841 未加载
评论 #37631842 未加载
评论 #37631373 未加载
wuiheerfojover 1 year ago
Perhaps I’m missing something, but when I’ve done this in the past, I get weird package resolution because my index.js isn’t in the root (`npm publish` publishes the root and doesn’t support alternate paths to my knowledge) - in the end people have to `import x from “mylib&#x2F;dist”`.<p>I got round this with some funky step where I copy the package.json into the dist folder and rewrite some paths. Is there a better way to do this?
评论 #37631511 未加载
评论 #37633597 未加载
评论 #37631299 未加载
评论 #37632863 未加载
评论 #37631430 未加载
评论 #37632703 未加载
aiunboxedover 1 year ago
Aslo interesting read on how to push a beta version <a href="https:&#x2F;&#x2F;kevinkreuzer.medium.com&#x2F;publishing-a-beta-or-alpha-version-to-npm-46035b630dd7" rel="nofollow noreferrer">https:&#x2F;&#x2F;kevinkreuzer.medium.com&#x2F;publishing-a-beta-or-alpha-v...</a><p>So that you can test without doing increments which are not required
game_the0ryover 1 year ago
&gt; Will it work with ES Modules (ESM) and CommonJS (CJS) style imports?<p>It&#x27;s so frustrating that in 2023 this is still a concern. It&#x27;s probably a bad idea when we adopt the latest JS language standards before they are implemented in the runtime env. Transpiling sucks.
评论 #37633452 未加载
revskillover 1 year ago
Maybe not related, but if a npm package has conditional exports, what&#x27;s current best way to patch that package.json ? I want to replace its condition exports with mine.
评论 #37633559 未加载
steve_taylorover 1 year ago
I still use Babel to do the transpiling, because tsc doesn’t support plugins, such as babel-plugin-styled-components.
meiralealover 1 year ago
I&#x27;m developing a npm package with just plain javascript modules. No more JS fatigue. I won&#x27;t ever go back to TypeScript and JS compilers, modern JavaScript is capable enough to stop all this madness.
评论 #37635830 未加载