Re:Ask HN: TypeScript config confusion
by w3456yhbvr5yh on Friday May 13, 2022 @08:39PM
(#31374007)
This is an accurate description of my experience also:
- trial & error
- leave it alone
- don't add stuff
I don't use babel or webpack and have many examples of "working" configs, but none of it adds up to a reproducible or stable process. Any random import might or might not `export` compatibly. The compiler barely helps, and people are left flipping toggles in the package.json and tsconfig.json hoping that some combo works for what they intend.
As far as the tsconfig goes, I'm with you there; the documentation is a little chaotic and a lot unhelpful. What I have learned to do is start a fresh one every time, enable the strictest settings I can, set up my source code and output structure explicitly (outDir, rootPath, etc.) based off of the comments in a fresh tsconfig.json file, and then leave it alone.
From the various blogs and forum posts I've seen, most people get tied up because they insist on adding all kinds of additional tooling up front. Babel, esbuild, snowpack, jest, the list goes on. Don't do that. Maybe later, if needed, but honestly tsc does the majority of that stuff just fine. Don't prematurely optimize your build and deployment timeline if you can't get imports to work yet.