TypeScript 7 · Utility types and narrowing
Write a type guard
Tell the compiler how a check narrows a value.
function isString(value: unknown): value is string {
return typeof value === "string";
}
Official TypeScript 7 documentation
More utility types and narrowing commands
- Make all properties optional
- Pick or omit properties
- Type a dictionary
- Require or freeze properties
- Remove null and undefined
- Narrow an unknown value
All utility types and narrowing commands · TypeScript 7 cheatsheet