Skip to content
Advertisement

how to get type of a colculated keyof T as a generic type in typescript

I have these two interfaces

JavaScript

and here is my use case elsewhere

JavaScript

I want to make save() return type to be same as id’s return type but in a generic type safe way how can I do that ?

Advertisement

Answer

You can declare another generic parameter that takes the property name in at compile time.

JavaScript

Then using it like this

JavaScript
Advertisement