typescript 提供的参数与调用目标的任何签名都不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35642053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:18:38  来源:igfitidea点击:

Supplied parameters do not match any signature of call target

typescriptangular

提问by Alex Ciobanu

I am getting this build error when I use a parameter decorator in a method. The class implements an interface. Here are the interface and class:

当我在方法中使用参数装饰器时,出现此构建错误。该类实现了一个接口。下面是接口和类:

export interface IClient{
    getServerConfig(): Observable<Response> ;

    getDashboard(): Observable<Response>;

    deploy(channelId: string): Observable<Response>;
}

export class Client implements IClient {

    public constructor( @Inject(Http) private http: Http, @Inject(Model) private config: Model) {
        super(http, config);
    }

    public getServerConfig(): Observable<Response> {
        return null;
    }

    public getDashboard(): Observable<Response> {
        return null;
    }

    public deploy(@Body('param') channelId: string): Observable<Response> {
        return null;
    }
}

When building I get this error

构建时出现此错误

Supplied parameters do not match any signature of call target.

right at the deploy function.

就在部署功能上。

The problem seems to be the parameter decorator next to the channelId parameter. Now I can't just remove it as I need it so I am wondering if there is a way to keep the interface definition and the decorator. Decorators are not allowed in interfaces so that is not an option.

问题似乎是 channelId 参数旁边的参数装饰器。现在我不能在需要时删除它,所以我想知道是否有办法保留接口定义和装饰器。接口中不允许使用装饰器,因此这不是一种选择。

Any ideas?

有任何想法吗?

采纳答案by basarat

Supplied parameters do not match any signature of call target.

提供的参数与调用目标的任何签名都不匹配。

Quickest fix is to do const BodyAny:any = Bodyand use BodyAny. Otherwise fix the type definition for Body.

最快的解决方法是做const BodyAny:any = Body并使用BodyAny. 否则修复Body.

回答by elwyn

I had the same error, and the problem was a missing @Injectable()on the service it was complaining about.

我有同样的错误,问题是@Injectable()它抱怨的服务缺失。

Simply importing and adding the decorator sorted it out!

只需导入并添加装饰器即可解决!