JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

[Typescript] Use never for readable string

发布时间 2023-03-30 00:34:38作者: Zhentiw
const demoFunc = <TObj extends {}>(obj: TObj, key: ErrorIfNever<keyof TObj, `You much pass at least one key`>) => {
  return obj[key as keyof TObj]
}

type ErrorIfNever<T, TError> = [T] extends [never] ? TError: T;

demoFunc({}, 'example')

 

    本栏目推荐文章
  • js string转html节点
  • day4: BigDecimal类, Arrays类, 包装类, String类 , Collection+迭代器,增强for
  • String 类和 STL (Standard Template Library)
  • Java中BigDecimal类、String类和Number类
  • 解决TypeError: string indices must be integers, not str
  • dlv调试时访问不可达函数报错please use a line with a statement
  • Linq Orderby null,string.Empty, 指定字符
  • [TypeScript]介绍及安装
  • vue报错:You may use special comments to disable some warnings. Use // eslint-disable-next-line to ignore the next line. Use /* eslint-disable */ to ignore all warnings in a file.
  • String字符串
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们