Allen Yu Allen Yu
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
  • Statement

  • Github

  • Twitter

    • Unocss VSCode extension @wheatjs
    • Unocss soo composable @Antfu7
    • sponsor-kit @Antfu7
    • vite-plugin-inspect @Antfu7
    • parallel asynchronous @SimonHoiberg
    • magic-string-extra @Antfu7
    • new-mdn @MozDevNet
    • podcasts-list @antfu7
    • test-in-javascript @antfu7
    • Widthout screen MacBook Pro @duanrui1205
    • File Nesting Config For VSCode @antfu7
    • VueUse Released V8 @VueUse
    • TypeScript Tip Record @SimonHoiberg
      • 今日句子
      • 原文
      • 翻译
      • 单词
      • 技术 - Record
    • Handle Time Traveling
    • Google 搜索小技巧
  • English
  • Twitter
2022-03-13
目录

TypeScript Tip Record @SimonHoiberg

# 今日句子

今日Twitter

# 原文

TypeScript Tip 💡

Use the utility type 'Record' to make an object indexable, instead of typing it out manually.
It's cleaner and becomes handy if you want to map the properties of one type to another.
> 查看原文 (opens new window)

# 翻译

TypeScript 技巧提示 💡

使用工具类型 Record 标记对象的索引,而不是手动输入。
如果你想将一个属性映射到另一个属性上,那将变得更简洁且方便。 查看原文 (opens new window)

# 单词

  • indexable:adj.可变址的;可加索引的;
  • manually:adv.手动的;用手
  • handy:adj.有用的,方便的,便于使用的;手巧的,有手艺的;手边的;附近的

# 技术 - Record

Record<K, T> 构造具有给定类型 T 的一组属性是 K 的类型。在将一个类型的属性映射到另一个类型的属性时,Record 非常方便

// bad
interface User {
  name: string
}
const users: { [key: string]: User } = {}

// good
interface User {
  name: string
}
const users: Record<string, user> = {}
#Twitter
Last Updated: 3/13/2022, 3:22:28 PM
VueUse Released V8 @VueUse
Handle Time Traveling

← VueUse Released V8 @VueUse Handle Time Traveling→

最近更新
01
4 月第 2 周总结
04-17
02
工具类型
04-01
03
Google 搜索小技巧
03-28
更多文章>
Theme by Vdoing | Copyright © 2018-2022 Allen Yu
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式