DEV Community

Discussion on: Default Props in React/TypeScript

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Oh, yeah - I'm definitely nodding along to everything you've written here. You probably have more C# experience than me, but I've done a good bit of it and enjoy it. I also use WebStorm and find that it does a really great job of tying most things together for me - and showing me when something seems out-of-place - without using TS.

And I love the description of "trying to explain to a compiler". That really sums up some of my frustrations here. If I'm writing "bad" code, or buggy code, then of course, I'd love for any tool to be able to point that out. But it's always frustrating if you've written something that you know works perfectly well - but the compiler/linter won't stop complaining about it.

Not sure if you read to the end of the article (and I totally understand if you didn't), but for the time being, I think that last "solution" is what I'm running with for now. It's actually not too much more verbose than using PropTypes.defaultProps. IMHO, it's still a little "ugly" - but not so much that it makes my dev eye start twitching.

Collapse
 
miketalbot profile image
Mike Talbot ⭐

I did make it to the end, but think I'd missed that you were so much closer in all of the "right!!" I was saying to the sections before haha.

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

Haha - I see your point.