TypeScript: Argument Validation

Only TS Generics to rescue

Explanation

I don’t think we need any explanation here. Basic TypeScript & Generics knowledge is enough to understand.

getOneById<T extends keyof Student>(id: number, fields: Record<T, 1>  ): Pick<Student, T>

References

Generics: https://www.typescriptlang.org/docs/handbook/2/generics.html
Utility types: https://www.typescriptlang.org/docs/handbook/utility-types.html#handbook-content
keyof Operator: https://www.typescriptlang.org/docs/handbook/2/keyof-types.html

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
LiftOff LLC

We are business accelerator working with startups / entrepreneurs in building the product & launching the companies.