typescript - 使用接口(interface)函数签名的函数参数

标签 typescript

我在接口(interface)中有一个函数签名,我想将其用作某个类中回调参数的签名。

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

我想做这样的事情:

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

这可能吗?

最佳答案

Is this possible?

是的如下图:

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

function validateFormat(validator: IGrid['gridFormat']) { // MAGIC 🌹
    // ...
}

关于typescript - 使用接口(interface)函数签名的函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44622399/

相关文章:

Typescript基于鉴别器的窄参数类型

typescript - 如何定义命名函数的类型?

typescript - 使用属性装饰器对属性类型进行严格类型检查

javascript - 在 Angular 中初始化具有一定数量元素的类数组

angular - typescript 编译器无法跳过导入的js文件

typescript - Visual Studio Code - 导入路径已损坏

javascript - 在 Angular 4 中 Plotly 找不到带有 ngIf 的 HTML 元素

javascript - TypeScript 中 c# 类虚拟成员的等价物

javascript - 如何将用户属性添加到 Javascript Azure Function 的服务总线主题输出

TypeScript 构建错误 : Build:An async function or method in ES5/ES3 requires the 'Promise' constructor