#What is the common setup for a typescirpt backend project?
36 messages · Page 1 of 1 (latest)
tsx/ts-node are mostly for quick iteration, not for prod. not everyone uses it though
Yeah if you are going with the tsc approach, you would properly setup rootDir and outDir so for example your src/**/*.ts compiles to dist/**/*.js.
I typically don't use a bundler and go with tsc in production, and tsx during development.
what if I want to minify?
you could get a bundler that supports that or an additional tool to do so
but typically you'll only need a bundler if you're packaging the project for, say, a browser environment
Can I get just one .d.ts file when I tsc? Now I'm getting multiple .d.ts files.
you can but it's generally not recommended
it can lead to collisions if they were originally modules
why do you want a single file?
you mean it's normal?
ok
I thought there should be only one .d.ts
because those packages only have one
yeah ts is just js with types, transpiling is just removing the types (for the most part, some older features do have some codegen)
so for each input ts, you'd gen an output js/d.ts
.ts ≈ .js + .d.ts
if they're manually written, having just 1 is pretty common. that's a different situation though
So on developing a typescript backend , should I emit this declaration files? Seems no need then
if it's an application, yeah no need
you'd need them if you wanted others to consume your code and get types, ie a library
So all librarys declaration files are manually written?
no
a ts project can just generate d.ts from the exist ts source, but existing js projects won't have types (unless they use jsdoc), so they'd need manual d.ts
You mean , library written in js manually writes d.ts?
yeah, sometimes they're too large for a rewrite to be easily feasible
Ok. what about library written in ts? how do they make d.ts?
or the maintainers don't have the resources to migrate or aren't interested, other developers can publish types for that library via DefinitelyTyped
they tell the compiler to emit d.ts
so they can emit just one d.ts?
Can tsc emit only one d.ts for the whole library?
@small geyser Man, I get it wrong. I thought that libraries written in ts also have just one d.ts 😅
When developing a typescript backend app, which value is correct for compilerOptions.module? NodeNext or ESNext?
!close
if you're using node, then node16 or nodenext, nodenext is a moving target.