Home  >  Q&A  >  body text

How to add correct type for ColumnSlots body function from PrimeVue

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

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, I will receive 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 type CorrectTypes.

I get slotProps as an array, what I should get is the type of the array member.

How do I declare this in typescript? Am I handling this the right way? I feel like I'm pretty close, but I might be on the wrong track.

P粉463291248P粉463291248108 days ago388

reply all(1)I'll reply

  • P粉180844619

    P粉1808446192024-04-07 00:24:41

    Well I did this a minute after writing the question and it worked...
    Still not sure if this is the best approach, but I'll post it anyway in case someone finds it useful.

    function myFunction(slotProps: Parameters) {
        const correctTypes = slotProps
    }
    

    reply
    0
  • Cancelreply