#How to extract type parameter from generic, in a generic way

5 messages · Page 1 of 1 (latest)

weary crownBOT
#
tickleme_pink#0

Preview:```ts
const x = new Set(["a", "b"])

type X = typeof x

type GenericTypeParam<T> = T extends Set<infer Y>
? Y
: never // How do I make this more generic, not just for a Set?

type XGenTypeParam = GenericTypeParam<X> //string

const data = [1, 2, 3, 2, 4, 3] as const
...```

primal gust
#

You could try making Set in the generic a type argument, and pass in Array for the array. Not sure if it works

earnest lark
primal gust
#

We can't pass a generic