[Typescript] “Record” Mapped Type

"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

上一篇:成为微信公众号开发者


下一篇:微信公众平台开发之对加密模式的解密