Check out what can go wrong if you leave unused variables and functions lying around. Unused pieces of code can clutter your codebase, but they can also cause some interesting bugs and even memory leaks. The former is easily fixed, the latter requires a refactor to remove the side effects from the constructor and turn them into a function that more clearly shows the intention. It is either a mistake and you meant to assign the object to a variable and use it later, or it implies that you are creating the object to use a side-effect contained in the object's constructor. Creating and dropping objects immediatelyĬreating an object but never using it is a code smell. Get your optional property declarations right and your interfaces will describe your objects the way you meant them to. While not necessarily a bug, this issue turns a type from something that communicates the intention of the developer to something that confuses. Starting with a type based issue, SonarLint often sees the combination of optional property syntax with union types that include `undefined`. In reverse order, our top 5 common TypeScript issues are: 5. With SonarLint in your editor, these issues can be caught as you write them, saving time and keeping your code clean and bug-free. From confusing types to memory leaks and hard-to-spot bugs, these issues could impact both your end users and the cleanliness of your code. Naturally, these are all common issues and the consequences they can have on your application vary quite a bit. This is a round-up of all the issues and where you can look to learn more about them. We dug into the SonarLint data to see which of its 300+ rules were invoked most often to flag a bug, code smell, vulnerability or security hotspot that could be caught before being committed. Over the past 5 weeks, we've been counting down our top 5 issues that SonarLint sees in TypeScript projects.
0 Comments
Leave a Reply. |