I want to write a generic function that accepts variable number of arguments that may have different types and returns a tuple based on those arguments. Here is an example in JavaScript: And in TypeScript I need to somehow convert the spread argument tuple to a resulting one: I’ve tried a naive approach of creating an overload for all reasonable
Tag: generics
how to get type of a colculated keyof T as a generic type in typescript
I have these two interfaces and here is my use case elsewhere 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 ? Answer You can declare another generic parameter that takes the property name in at compile time. Then using it like this
TypeScript function that works on all numerical array types
I am trying to write a function that works on all of the JavaScript array types, e.g. on number[], Float32Array etc. It should return the same type that it gets as a parameter. A simple example would be: The function should be able to use all methods common to all array types (not just map). I also tried but I