#What is the common setup for a typescirpt backend project?

36 messages · Page 1 of 1 (latest)

small geyser
#

the "vanilla"/typical approach is to use tsc to generate a folder for built code. similar to your second bullet, but actually configured (i don't think anyone intentionally has compiled files next to their source files)

#

tsx/ts-node are mostly for quick iteration, not for prod. not everyone uses it though

fresh temple
#

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.

tropic nacelle
#

what if I want to minify?

small geyser
#

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

tropic nacelle
#

Can I get just one .d.ts file when I tsc? Now I'm getting multiple .d.ts files.

small geyser
#

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?

tropic nacelle
#

you mean it's normal?

#

ok

#

I thought there should be only one .d.ts

#

because those packages only have one

small geyser
#

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

small geyser
tropic nacelle
#

So on developing a typescript backend , should I emit this declaration files? Seems no need then

small geyser
#

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

tropic nacelle
small geyser
#

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

tropic nacelle
#

You mean , library written in js manually writes d.ts?

small geyser
#

yeah, sometimes they're too large for a rewrite to be easily feasible

tropic nacelle
#

Ok. what about library written in ts? how do they make d.ts?

small geyser
#

or the maintainers don't have the resources to migrate or aren't interested, other developers can publish types for that library via DefinitelyTyped

small geyser
tropic nacelle
#

so they can emit just one d.ts?

#

Can tsc emit only one d.ts for the whole library?

tropic nacelle
#

@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?

tropic nacelle
#

!close

small geyser