這是來自 Column.d.ts 的 PrimeVue ColumnSlots(縮短)
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[];
}
這是我的函數,我將從 ColumnSlots 接收正文類型
function myFunction(slotProps: Parameters<ColumnSlots["body"]>) {
const correctTypes = slotProps[0]
}
這是我目前擁有的,但 slotProps 應該是 CorrectTypes 的類型。
我將 slotProps 作為數組獲取,我應該獲取的是該數組成員的類型。
我該如何用打字稿聲明這一點?我是否以正確的方式處理這件事?我覺得我已經很接近了,但我也可能走錯路了。
嗯,我在寫完問題後一分鐘就這樣做了,它成功了......
仍然不確定這是否是最好的方法,但無論如何我都會發布它,以防有人發現它有用。