DEV Community

loading...

Discussion on: Handling Safe Destructuring in TypeScript

Collapse
rdeneau profile image
Romain Deneau

Great article 👍
It's a pleasure to see craft principles applied in TypeScript leading to better code 🎉

📝 To be noticed:

  • A type assertion (as T), as long as "T" is not any or unknown, is not totally unsafe: main type compatibility checkings are done. Type assertions are just more tolerant than type annotation (: T) especially regarding required properties. Sometimes, code can be refactored from as T to : Partial<T> to get back full type safety.
  • We can use type inference to reduce payload: ResponsePayload = defaultPayload into payload = defaultPayload.