<aside> š” Original Post by Martin Hochel: https://medium.com/@martin_hotell/10-typescript-pro-tips-patterns-with-or-without-react-5799488d6680
</aside>
š this article uses following library versions:
{ "@types/react": "16.4.16", "@types/react-dom": "16.0.9", "typescript": "3.1.3", "react": "16.5.2", "react-dom": "16.5.2"}š®Ā source code can be found on my github profile
TypeScript is definitely the best thing that happened to JavaScript. period.
Unfortunately, I cannot say the same about āThe best thing that happened to Java/C# devs writing JavaScript with it šš³šā±ā
Why �
Well, it definitely makes your Java/C# alter ego feel like home, having types within JavaScript (which is amazing !), but then, it introduces other ālanguage featuresā which are not part of standard JavaScript, and because of those, it may throw a false prejudice about TypeScript, by putting it to a āCompletely new languageā bag, which isnāt really true IMHO.
Iāve beenĀ always trying to stay away from various TS features (for a good reasons šexplained in this article) to stay in Idiomatic/Standard JavaScript land as much as possible.
This article describes various patterns/tips that I āinvented/learnedā and have been using while using TypeScript and React for building UIās.
NOTE:Initially, this blog post introduced āonlyā 10 tips, During review of this post I already added 8 more šŖ. I may add additional ones in the future as React patterns/TS capabilities change/improve/evolve. Make sure to check this post time to time for any updates š
26.1.2019Ā updated tip#9 šUse type inference for defining Component State or DefaultProps23.1.2019Ā added tip#19 š Use type alias instead of interface for declaring Props/State#20 š Donāt useĀ FunctionComponent<P>Ā to define function component
Whole article is written like an āstyle guideā with 3 sub-sections for every tip/pattern which consists of:
With that covered, letās hop into 10++ TypeScript Pro tips/patterns with ( or without ) React.
publicĀ accessor within classesDonāt:
