[Typescript 5.3] returnWhatIPassIn

发布时间 2023-12-13 02:01:46作者: Zhentiw
const returnWhatIPassIn = <const T extends any[]>(t: T) => {
  return t;
};

// result is any[] in TS 5.2, but ['a', 'b', 'c'] in 5.3
const result = returnWhatIPassIn(["a", "b", "c"]); // type as ["a", "b", "c"]