I am converting an existing vue project (written in JS) to Typescript. I am mostly getting on well, but am having a problem with passing an array as props to a component. I am using Composition API / SFC.
For one component (which doesn't need an array), I have this structure:
<script setup lang="ts">
import type { TrackTile } from '../../env.d';
interface Props {
tile: TrackTile,
item: number
}
const props = defineProps<Props>()
console.log('keyItem script setup');
console.log(props.tile);
</script>
This transpiles without errors and then runs fine, so I assume my basic syntax is OK here.
But another component mainGrid needs to be given an array of TrackCell types:
<script setup lang="ts">
import type { TrackCell } from '../../env.d';
interface Props {
grid: TrackCell[][];
}
const props = defineProps<Props>()
console.log('mainGrid script setup');
console.log(props.grid[0][0]);
</script>
The component is called from its parent like this:
<mainGrid :grid = trackGrid>
</mainGrid>
In this case I get an error that props.grid[0] is undefined.
As a check to ensure that the trackGrid array (and its constituent trackCells) was defined and populated correctly, I temporarly moved the template for the mainGrid component into its parent, and everything then works as expected. So it appears that it's just the `defineProps' section which is incorrect.
trackGrid is reactive:
export const trackGrid: TrackCell[][] = reactive([] );