Skip to content

Instantly share code, notes, and snippets.

View devesh-anand's full-sized avatar
:octocat:
Code, sleep. Repeat the streak.

Devesh Anand Srivastava devesh-anand

:octocat:
Code, sleep. Repeat the streak.
View GitHub Profile
@devesh-anand
devesh-anand / ts-practices.md
Last active February 8, 2024 08:23
Some typescript coding practices
  • Never use any.
  • In case there's no alternative, use unknown (more about unknown).
  • Use ReadOnly arrays to ensure there's no scope for mutation (unless mutation is needed).
const numbers: ReadonlyArray<number> = [1, 2, 3];
  • Array generics over typecasting.
const numbers: Array<number>;
//instead of const numbers: any[];