ystrdy的博客

记录学习路上的一些笔记


  • Home

  • Archives

typescript将字符串数组转换为类型

Posted on 2019-06-03
1
2
3
4
5
6
function asLiterals<T extends string>(arr: T[]): T[] { return arr; }

const s = asLiterals(['foo', 'rolo', 'zoombaz']);
// s => ('foo' | 'rolo' | 'zoombaz')[]
type v = {[K in (typeof s)[number]]: string};
// v => { foo: string, role: string, zoombaz: string }
# typescript type array
git clone一个github上的仓库太慢
npm安装puppeteer失败

ystrdy

10 posts
9 tags
GitHub E-Mail
© 2019 ystrdy