Day 13 of 14 35 minPromise<T>Typing API dataRuntime validation
Type asynchronous code and the data that comes from outside your program. Annotate promises and async functions, type Promise.all results, handle errors as unknown, and validate API responses at runtime instead of trusting them.
By the end of today you can
- Type async functions and promises with Promise<T>
- Get precise types from Promise.all
- Handle caught errors safely as unknown
- Explain why API data must be validated at runtime
- Validate responses with type guards or a schema library like Zod
What's inside
- 6 sections
- 2 diagrams and mind maps
- 5 code examples you can run
- 5-question quiz
- 1Typing async functions
- 2Promise.all keeps the types
- 3Errors are unknown
- 4The boundary problem
- 5Validating with a type guard
- 6Schema libraries: Zod
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free