Don't Put Your Types In .d.ts files #typescript

preview_player
Показать описание
Become a TypeScript Wizard with my free beginners TypeScript Course:

Follow Matt on Twitter

Join the Discord:

Комментарии
Автор

Need an example of an advance typescript developer uses d.ts!

prismqubic
Автор

Yes this is a good callout. I have engineers on my team that ask about d.ts and I just tell them you basically never need to use them so don't worry about it until you get much more advanced with TS.

thomasini
Автор

I think this differs when it comes to libraries vs application code.
Build tools are currently not great at extracting the desired types for publishing. Commonly you’ll see the exposed types in a .d.ts file which is simply copied over to the dist folder when building

brukts
Автор

I used to get this wrong and even after I was told not to do it, I didn’t know why until now. Thank you!

flygonfiasco
Автор

Module augmentation also belongs in the .d.ts file :)

JlNGLEZ
Автор

Let's look at a case where I'm using jsdoc with Js and I don't want to write all my types using jsdoc. Is it okay to put my types in d.ts files?

thelazycoder
Автор

what would be some examples of "very advanced" stuff?

aprilmintacpineda
Автор

ok but if you don't do "declare" in these files then you're not changing anything globally. isn't that kinda ok?

sohrb
Автор

This would be incorrect on libraries as d.ts would have types and .js instead of .ts will have the logic to ensure compatibility

nithinsvarrier
Автор

Imagine you have a type you want to use all around your project, a generic, or a bunch of constants - That's what you put in d.ts files.

shapelessed
Автор

could you elaborate on why is this not a good practice? i thought i understood .d.ts, but apparently i know very little about it. I'd gladly watch a video of yours on the subject

felipe
Автор

I can't imagine people did this mistake.

aArcziMetin
Автор

I put everything in my ts files…
The only .d.ts files in my repo are generated ones

EnbyCherry
Автор

"I see a lot of people getting this wrong" I have seen this 0 times. I actually thought d.ts files were like an automatic extraction of compiled typescript types for external use (such as for those who use your published package)

carlosmspk
Автор

I have a counter example, put a plain interface in a .ts file then tell me what that emitted file contents will be 😂

yn-yt