Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I write TypeScript projects in TypeScript from the start. If I have an existing JS project that needs to port to TypeScript then I will rewrite it entirely in TypeScript. Yes, that takes some small amount of time, but it’s never a complete rewrite. It’s mostly just minor syntax updates as the actual runtime should remain the same as validated by test automation.

I type everything I declare whether a primitive or not. My complex types like data structures, objects, and modules get typed as interfaces. I write them as I need them. I also have lint rules that check for missing type declarations.

Don’t over think any of this. None of this exists as an exercise in code masturbation. There are two immediate values to TS: warning on unintended type coercion and predictive rapid refactoring. So, just keep plan your software appropriately and keep everything simple.



But why would any of that need to be done manually in a .d.ts file? You can just write your type definitions in ts files


Types are meta data for the compiler. They are not code that is compiled to JavaScript, so I isolate my type definitions to d.ts files. That is the only reason I have d.ts files at all.


Types are also documentation for the developers reading and editing the code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: