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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article 👍
It's a pleasure to see craft principles applied in TypeScript leading to better code 🎉
📝 To be noticed:
as T
), as long as "T" is notany
orunknown
, 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 fromas T
to: Partial<T>
to get back full type safety.payload: ResponsePayload = defaultPayload
intopayload = defaultPayload
.