Relative Content

Tag Archive for typescripttypestypescript-generics

Tuple that accepts only one occurrence of specific type

I’m trying to write a function that accepts a tuple of a union type but a specific member of the union should only appear once (or not at all), e.g. [A, B, A] is valid but [A, B, A, B] is not. Ideally I could just write something like [...A[], B, ...A[]] | A[] but TypeScript doesn’t allow it.

Complex generic return type in TypeScript

I’m trying to create a generic return type for this function, but I’m struggling hard. I’ve managed to get the keys but only if I changed QueryParam to QueryParam<T extends string> and use the generic type parameter T for name, but the values were all type of never.