TypeScript

TS Handbook and this article are great intros.

Notes

  • TypeScript can figure the return type out by looking at the return statements, so we can also optionally leave this off in many cases
  • You really shouldn’t use arrow function as class members. Arrow functions are duplicated in memory for each class instance, while proper method members are written once in your class’s prototype and shared between all instances.
  • Unlike classes, an interface is a virtual structure that only exists within the context of TypeScript. The TypeScript compiler uses interfaces solely for type-checking purposes.
  • any means “ignore the type”, unknown means “we don’t know the type”, which aren’t the same thing, and for better code you’d rather not know the type than ignore it.
  • You can’t use unknown as a simple replacement for any, that wouldn’t make sense. unkwnown carries the implication that you should not use this variable other than passing it around. Or testing its type to get rid of the “unknown” state.

results matching ""

    No results matching ""