I have a property on a component that worked in JavaScript, but have problems with Typescript:
props: {
keep_open: {
type: Array,
default: () => [],
}
}
This definition doesn't fail here, but later in the code:
let keepOpen: Array<string> = [this.data.popupId];
this.keep_open.forEach((id) => {
keepOpen.push(id);
});
The id from Keep_Open is type undefined and will not push into KeepOpen.
How do I fix this, either in the later code or in the definition of the properties?
CodePudding user response:
as mentionedin the vue documentation you should use PropType
from vue
, so it should be something like
type: Array as PropType<string[]>
And as good practice ,don't change value of a props inside a composant , emit an event and the owner of the props should update it.