I have a component which receives 3 arrays as props, and I want to concatenate them all together before rendering. But I keep getting these TypeScript errors:
<script lang="ts">
import {RisikoentitetRevision, IdentitetsmarkoerRevision, RisikomarkeringRevision} from '@/model/Risikoentitet'
import {defineComponent, computed, PropType} from 'vue'
export default defineComponent({
name: 'HistorikLogTabel',
props: {
risikoentitetRevisioner: {
type: Array as PropType<RisikoentitetRevision[]>,
required: true,
},
identitetsmarkoerRevisioner: {
type: Array as PropType<IdentitetsmarkoerRevision[][]>,
required: true,
},
risikomarkeringRevisioner: {
type: Array as PropType<RisikomarkeringRevision[][]>,
required: true,
},
},
setup(props) {
console.log({props})
const allRevisions = computed(() => {
console.log("2nd", {props})
return [
...props.risikoentitetRevisioner, // TODO: TS2488: Type 'unknown' must have a '[Symbol.iterator]()' method that returns an iterator.
...props.identitetsmarkoerRevisioner.flat(), // TODO: TS2339: Property 'flat' does not exist on type 'unknown'.
...props.risikomarkeringRevisioner.flat(), // TODO: TS2339: Property 'flat' does not exist on type 'unknown'.
]
})
return {
allRevisions,
}
}
})
</script>
I’m not quite sure what I’m doing wrong. I have tried passing props into the argument in computed but it made no difference.
EDIT:
There is a workaround to ignore the TS errors, and the logic still works as expected. But it is not optimal and I would really like to find out what the TS problem is.
const allRevisions = computed(() => {
console.log("2nd", {props})
return [
// @ts-ignore
...props.risikoentitetRevisioner, // TODO: TS2488: Type 'unknown' must have a '[Symbol.iterator]()' method that returns an iterator.
// @ts-ignore
...props.identitetsmarkoerRevisioner.flat(), // TODO: TS2339: Property 'flat' does not exist on type 'unknown'.
// @ts-ignore
...props.risikomarkeringRevisioner.flat(), // TODO: TS2339: Property 'flat' does not exist on type 'unknown'.
]
})
console.log({allRevisions})