How to add correct type for ColumnSlots body function from PrimeVue
P粉463291248
P粉463291248 2024-04-06 11:50:20
0
1
650

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粉463291248
P粉463291248

reply all(1)
P粉180844619

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
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template