function processValue<T extends string[]>(arr: T, callback: (...args: { [K in keyof T]: T[K] extends 'number'? number : T[K] extends 'boolean'? boolean : T[K] } ) => void) {
const types: string[] = arr;
const args: any[] = [];
types.forEach(type => {
if (type === 'number') {
args.push(1);
} else if (type === 'boolean') {
args.push(true);
} else {
args.push(type);
}
});
callback(...args);
}
// 测试代码
processValue(['number', 'boolean'], (num: number, bool: boolean) => {
console.log(`数字: ${num}, 布尔值: ${bool}`);
});
processValue(['string', 'number'], (str: string, num: number) => {
console.log(`字符串: ${str}, 数字: ${num}`);
});