TSTypeScript · Lesson 8 of 10
Async TypeScript
TypeScript's async types are straightforward once you know the pattern: async functions return `Promise<T>`, and `await` unwraps them to `T`. The tricky part is typing errors, which TypeScript forces you to acknowledge.
◆ Note
In TypeScript, `catch (err)` gives you `unknown`, not `Error` — because anything can be thrown. Always check `err instanceof Error` before accessing `.message` or `.stack`. The Result<T> pattern above avoids this entirely by keeping errors in the return value.
In TypeScript, `catch (err)` gives you `unknown`, not `Error` — because anything can be thrown. Always check `err instanceof Error` before accessing `.message` or `.stack`. The Result<T> pattern above avoids this entirely by keeping errors in the return value.