Vue3 / Typescript 定义一个 属性 的 Array(string)

Vue3 / Typescript define an property of Array(string)

我在 JavaScript 中工作的组件上有一个 属性,但 Typescript 有问题:

props: {
   keep_open: {
     type: Array,
     default: () => [],
   }
}

这个定义在这里并没有失败,但在后面的代码中:

let keepOpen: Array<string> = [this.data.popupId];
this.keep_open.forEach((id) => {
   keepOpen.push(id);
});

来自 Keep_Open 的 ID 类型未定义,不会推送到 KeepOpen。​​

如何在后面的代码或属性定义中解决这个问题?

如 vue documentation 中所述,您应该使用 vue 中的 PropType,因此它应该类似于

type: Array as PropType<string[]>

作为良好的做法,不要更改组合中道具的值,发出一个事件,道具的所有者应该更新它。