Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function parameter to use interface's function signature

Tags:

typescript

I have a function signature in an interface which I'd like to use as the signature for a callback parameter in some class.

export interface IGrid {
    gridFormat(gridCell: GridCell, grid: Grid): boolean
}

I'd like to do something like this:

validateFormat(validator: IGrid.gridFormat) {
    // ...
}

Is this possible?

like image 848
el_pup_le Avatar asked Nov 21 '25 06:11

el_pup_le


1 Answers

Is this possible?

Yes as shown below:

export interface IGrid {
    gridFormat(gridCell: GridCell, grid: Grid): boolean
}

function validateFormat(validator: IGrid['gridFormat']) { // MAGIC 🌹
    // ...
}
like image 110
basarat Avatar answered Nov 25 '25 00:11

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!