zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[TypeScript] Ensure params not accept certain type

typescript not type params accept ENSURE
2023-09-14 08:59:12 时间

Let's say we have a function accept any type but array.

function anyTypesButNotArray<T>(
  val: T extends any[] ? "you should not pass in array" : T
) {
  return val;
}

anyTypesButNotArray(["sf", "sdf"]);