TypeScript · Lesson 67 of 120
ReturnType and Parameters
Types from functions.
Sometimes the only place a type is written is a function. ReturnType gives you what a function returns. Parameters gives you its parameters, as a tuple.

- Types in functions
- ReturnType
- Parameters
Reusing a function's types
Make order returns an object we never named. ReturnType of typeof make order gives us that type anyway. Parameters gives the argument types, as a tuple. Run it.
app.tstypescript
function makeOrder(customer: string, total: number) {
return { id: Math.floor(1000 + total), customer, total, status: "packing" as const };
}
type Order = ReturnType<typeof makeOrder>;
type OrderArgs = Parameters<typeof makeOrder>; // [customer: string, total: number]
const args: OrderArgs = ["Priya", 65];
const order: Order = makeOrder(...args);
console.log(order);Output
{ id: 1065, customer: 'Priya', total: 65, status: 'packing' }Summary
ReturnType and Parameters pull types out of functions, so you don't repeat them. Next, conditional types.
Key takeaways- ReturnType<typeof f>
- Parameters<typeof f>
- No repeats
Next up: Conditional Types — if for types