1
我想不通为什么我得到了这样的错误:接口签名不匹配
export interface IGrid {
(gridCell: GridCell): boolean
}
在我的课堂我有
foo(gridCell: GridCell): boolean {
return true;
}
错误:
Class 'X' incorrectly implements interface 'IGrid'. Type 'X' provides no match for the signature '(gridCell: GridCell): boolean'
更新:
我已经为接口的gridFormat签名添加了一个参数。
export interface IGrid {
gridFormat(gridCell: GridCell, x: number): boolean
}
类:
gridFormat(gridCell: GridCell): boolean {
return true;
}
现在的问题是没有错误,类没有实现与x: number
放慢参数的功能。我怎样才能让界面正确地要求功能。
好吧,这工作,但我还是不能让我的接口工作如何我想它。我已经更新了这个问题。签名不匹配,但没有错误。 –
@el_pup_le这实际上是由设计。参见[此](https://stackoverflow.com/questions/35541247/typescript-not-checking-function-argument-types-declared-by-interfaces)和[此](https://github.com/Microsoft/ TypeScript/wiki/FAQ#why-are-functions-with-less-parameters-assignable-to-functions-that-take-more-parameters) – Saravana
谢谢,这很令人沮丧。我看你是C#的人,你知道C#是否被设计成这样吗? –