2

So I would like one type to be specified by the user but the other to be inferred from the argument

simplest example

export function state<D, T extends string = string>(type: T) {
  return [] as Array<D | T> 
}

var b = state<number>('fooBarTest'); // (string, number)[]

I would like typeof b to equal

var b = state<number>('fooBarTest') // (number | "fooBarTest")[]` 

without needing to write

var b = state<number, 'fooBarTest'>('fooBarTest') // (number | "fooBarTest")[]` 

Is it possible?

lonewarrior556
  • 3,917
  • 2
  • 26
  • 55

0 Answers0