打字稿返回键值对数组

时间:2021-04-25 06:29:02

标签: javascript typescript

对下面的鞋子函数的返回类型是什么感到困惑?

export interface myShoes {
  useCase: string
  color: string
  pic: string
  price: string
}
const myShoesMap = {
  tennisShoes: {
    useCase: 'tennis',
    color: 'green',
    pic: 'racquet',
    price: 'alot',
  },
}

public shoes(): { [key: string]: myShoes } {
    return myShoesMap
  }

在我看来,我是如何阅读它的,它正在返回一个对象,其中包含字符串类型的键?有人可以解释这种返回类型的含义以及如何优化它吗?谢谢

0 个答案:

没有答案