How to describe the type of a dictionary in typescript more efficient, than the solution below?
type DictEntry = { [key: string]: string }
type UploadDict = { [key: string]: DictEntry }
const UPLOAD_TYPE_DICT: UploadDict = {
JPG: {
label: "jpg",
type: "image/jpeg",
},
PNG: {
label: "png",
type: "image/png",
},
}
>Solution :
If you mean a cleaner syntax with more efficiently use Record.
type DictEntry = Record<string, string>
type UploadDict = Record<string, DictEntry>
const UPLOAD_TYPE_DICT: UploadDict = {
JPG: {
label: "jpg",
type: "image/jpeg",
},
PNG: {
label: "png",
type: "image/png",
},
}