等同于 PropTypes.arrayOf 的 TypeScript 声明是什么?

What is the TypeScript declaration equivalent of PropTypes.arrayOf?

我希望将 PropTypes 转换为 Typecript 声明。

我能找到其中大部分的对应项,但我不知道这个:

fruits: PropTypes.arrayOf(PropTypes.oneOf(['apple', 'banana', 'cherry', 'dewberry']))

我最好的尝试是:

fruits: any[]

但它应该针对所列项目。

以下可能是 属性 个水果的有效值和无效值:

// Valid
fruits: ['apple']
fruits: ['cherry', 'dewberry']
// Invalid
fruits: ['my', 'little', 'pony']

感谢您的帮助!

像这样:

type fruit = 'apple' | 'banana' | 'cherry' | 'dewberry'

type fruits = fruit[]

const a:fruits = ['apple'] // ok
const b:fruits = ['cherry', 'dewberry'] // ok
const c:fruits = ['my', 'little', 'pony'] // error

TS playground 上试用。