首页 > 移动平台 > 详细

[Typescript] “Record” Mapped Type

时间:2020-10-02 00:06:29      阅读:44      评论:0      收藏:0      [点我收藏+]

"Record" repersent key-value pair.

type MyRecord<K extend string, T> = {
   [P in K]: T       
}

 

Record key should be string.

array[0]

in javascript, even we give array 0 as key, it still convert to string "0"

array[0] 
array["0"]

they are the same.

 

let dictionary: Record<string, TrackStates> = {}

interface TrackStates {
    current: string;
    next: string;
}

const item: Record<keyof TrackStates, string> = {
    current: ‘abc‘,
    next: ‘‘def
}

dictionary[0] = item

 

[Typescript] “Record” Mapped Type

原文:https://www.cnblogs.com/Answer1215/p/13758773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!