I'm creating a nestjs API so I'm using classes to declare my entities for example
export class Customer {
id: number;
name: string;
}
So now I'm working in my Customer Controller and I would like to type an get query param as customer.id because I'm thinking if some day the customer id data type changes to string automatically making my controller query param as string too.
@GET()
getCustomerById(@Params('id', id: Customer.id)) {
return this.customerService.getCustomerById(id))
}
Is it possible? Thanks
You can use TypeScript lookup types:
getCustomerById(@Params('id') id: Customer['id']) {}