提供的参数与调用目标的任何签名都不匹配 - Typescript
Posted
技术标签:
【中文标题】提供的参数与调用目标的任何签名都不匹配 - Typescript【英文标题】:Supplied parameters do not match any signature of call target - Typescript 【发布时间】:2017-04-28 18:04:12 【问题描述】:我有一个名为 FilterOperation.ts 的模型,如下所示:
export class FilterOperations
constructor(
public mainFilter : string,
public currencyType : string,
public status : string
)
然后像这样定义我的组件:
import Component, OnInit, Input from "@angular/core";
import FormsModule from '@angular/forms';
import 'rxjs/operator/finally';
//models
import Session from './src/models/session';
import Client from './src/models/client';
import Operation from './src/models/operation';
import FilterOperations from './src/models/filterOperations';
//services
import OperationSearchService from './src/services/operations_admin.service';
//constants
import * as constantsValues from "../../core/constants/constants";
@Component(
templateUrl: './app/views/operations_admin/src/templates/operations_admin.html',
styleUrls: ['./app/views/operations_admin/css/operations_admin.css'],
providers: [ OperationSearchService ]
)
export class OperationsAdminComponent implements OnInit
@Input() filter: FilterOperations;
errorMessage: string;
clientFound: Client;
sessionList: Session[];
operationCount: number;
mainSearchSelector: string;
constructor (private operationSearchService: OperationSearchService)
ngOnInit()
this.filter = new FilterOperations(); //HERE GOES THE ERROR
onChangeMainFilter(newValue)
this.mainSearchSelector = newValue;
findOperations()
//some code
当我尝试编译它时,它一直发送相同的消息:“提供的参数与调用目标的任何签名都不匹配”。初始化过滤器的值时我做错了什么:
this.filter = new FilterOperations();
【问题讨论】:
【参考方案1】:FilterOperations
的代码:
export class FilterOperations
constructor(
public mainFilter : string,
public currencyType : string,
public status : string
)
相当于:
export class FilterOperations
public mainFilter: string;
public currencyType: string;
public status: string;
constructor(mainFilter: string, currencyType: string, status: string)
this.mainFilter = mainFilter;
this.currencyType = currencyType;
this.status = status;
虽然你可能打算这样做:
export class FilterOperations
public mainFilter: string;
public currencyType: string;
public status: string;
constructor()
在前两个中,构造函数需要 3 个参数,但是当你实例化它时你没有传递任何参数:
this.filter = new FilterOperations();
如果您想要一个空的 ctor,请使用我的第三个代码 sn-p。 你也可以这样做:
export class FilterOperations
constructor(
public mainFilter?: string,
public currencyType?: string,
public status?: string
)
现在所有参数都是可选的,您可以在没有参数的情况下调用 ctor。
【讨论】:
public
关键词很重要以上是关于提供的参数与调用目标的任何签名都不匹配 - Typescript的主要内容,如果未能解决你的问题,请参考以下文章
Angular2 - 提供的参数与调用目标的任何签名都不匹配
C# DllImport“调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配 ”