DEV Community

loading...

Discussion on: React PropTypes vs Typescript! Any experience?

Collapse
juanmaguitar profile image
JuanMa • Edited

I'm new to Typescript and after reading this discussion (and some related articles) it makes all the sense in the world to use Typescript over propTypes.

But by checking some of the most populars React Component Libraries projects

like Material-IU:

or Semantic UI React

or React Toolbox

...it seems some big projects are using both.
So, i'm a bit confused about this. And i don't really get the purpose of these *.d.ts files

Why are they using both? What is the purpose of the *.d.ts files?
How does this fit in a react development workflow?

Can anyone shed some light on this? :)

Thanks in advance!!

Collapse
inhumanan profile image
manan vaghasiya

You are right, I have also seen some popular projects using both typescript types and proptypes but couln't understand why.

Here is ant-design using both

Collapse
joemaffei profile image
Joe Maffei

Why are they using both? What is the purpose of the *.d.ts files?

Because even though the project doesn't use Typescript directly, someone using their library/framework might be developing in Typescript. If the library doesn't have .d.ts files, those developers would have to build type definitions themselves. That's not something you want to do when you just want to import a component into your project (trust me, I've been there.)