TypeScript - Best practices and conventions

There are some practices that are highly recommended to be considered as a standard within your codebase. They will affect future refactors and help maintain a healthy state of the type system.

TypeScript truly shines when the entire codebase is strictly typed. ???? 2023, author of this roadmap

Type vs interface

I know that we should define a consistent typing method throughout the codebase to ensure the use of the same approach

Do not use

I know that non-primitive boxed objects like String (not string) should never be used

I understand that I should avoid using any and object

Function return types

I know that we should establish consistent rules for typing function types within specific parts of the code. I understand the impact of the decision between inferred and typed return types on refactoring and the consistency of utilities

I'm aware that I need to include return types for recursive functions

Use tuples

I know I should mostly use tuples when returning fixed-length arrays

Icon of TypeScript
Icon of Best practices and conventions
TypeScript skill
suggested
Best practices and conventions
Ready to learn
Required technologies

I know that we should define a consistent typing method throughout the codebase to ensure the use of the same approach

I know that non-primitive boxed objects like String (not string) should never be used

I understand that I should avoid using any and object

I know that we should establish consistent rules for typing function types within specific parts of the code. I understand the impact of the decision between inferred and typed return types on refactoring and the consistency of utilities

I'm aware that I need to include return types for recursive functions

I know I should mostly use tuples when returning fixed-length arrays

Close
Loading content