Company
Date Published
Author
Phil Nash
Word count
617
Language
English
Hacker News points
None

Summary

We recently looked at how you can get some of the benefits of TypeScript in our JavaScript code base. If you've been through that process, then TypeScript is already helping to keep some type issues out of your JavaScript. But, because it is acting on JavaScript, TypeScript will not be able to infer as much as it would like to. The good news is that we can give TypeScript more hints about the types that flow around our JavaScript application without changing the project to TypeScript. Adding more types using JSDoc and/or declaration files can provide this information, helping TypeScript understand your JavaScript better, which in turn helps IDEs make better suggestions and tools like SonarQube apply rules to source code. By giving more type information, you can still use JavaScript while benefiting from some of the features of TypeScript, such as better error messages and type checking, making it easier for developers to maintain and extend your application.