Is there a way to force TypeScript to infer type as specific values passed into function, not a general type?
function infer<T>(...args: T[]): T[] {
return args;
}
const numbers = infer('one', 'two'); // Inferred type of numbers: string[]
// Desired type of numbers: ('one' | 'two')[]
I know I can achieve desired type by writing infer<'one' | 'two'>('one', 'two') but I'd like to not repeat myself.