Search code examples
typescriptvue.jsprimevue

How to add the correct type for ColumnSlots body function from PrimeVue


This is PrimeVue ColumnSlots from Column.d.ts (shortened)

export interface ColumnSlots {
    /**
     * Custom body template.
     * @param {Object} scope - body slot's params.
     */
    body: (scope: {
        /**
         * Row data.
         */
        data: any;
        /**
         * Column node.
         */
        column: Column;
        /**
         * Column field.
         */
        field: string;
        /**
         * Row index.
         */
        index: number;
        /**
         * Whether the row is frozen.
         */
        frozenRow: boolean;
    }) => VNode[];
}

This is my function where I'm going to recieve the body type from ColumnSlots

function myFunction(slotProps: Parameters<ColumnSlots["body"]>) {
    const correctTypes = slotProps[0]
}

This is what I currently have, but slotProps should be of the type that correctTypes is.

I am getting slotProps as an array and what I should be getting is the type of the member of that array.
How do I declare that with typescript? And am I even going about this the right way? I feel like I'm really close but I could have also just went the completely wrong way here.


Solution

  • Well, I did this 1 minute after writing up the question and it worked...
    Still unsure if it's the best way to go but I'm posting it anyway in case someone finds it useful down the road.

    function myFunction(slotProps: Parameters<ColumnSlots["body"][0]>) {
        const correctTypes = slotProps
    }