简体   繁体   English

属性在角对象的类型对象上不存在

[英]Property does not exist on type object in angular

I have an object while running i am getting the following error as Property doesn't exist on type object can anyone tell me what am i doing wrong in it. 我在运行时有一个对象,但由于类型对象上的属性不存在,因此出现以下错误,任何人都可以告诉我我在做什么错。

let filter = {
      project: 'Test',
      flow: 'basic',
      start: 0,
      length: 3
    };

Error: 错误:

    src/app/_services/flow.service.ts(14,39): error TS2339: Property 'project' does not exist on type 'object'.
src/app/_services/flow.service.ts(14,62): error TS2339: Property 'flow' does not exist on type 'object'.
src/app/_services/flow.service.ts(14,83): error TS2339: Property 'start' does not exist on type 'object'.
src/app/_services/flow.service.ts(14,106): error TS2339: Property 'length' does not exist on type 'object'.

You probably have filter typed as object[] as well. 您可能也已将filter键入为object []。 And property project does not exist on object. 属性project在对象上不存在。 If you don't care about typing, you can declare filter as Array<any>: 如果您不关心键入,则可以将filter声明为Array<any>:

let filter: Array<any>;

这样做,问题就消失了,

private filter: any[];

The problem may be with your flow.service.ts field where you have set that to type object and all the field in filter don't exist on the type object . 问题可能出在您的flow.service.ts字段中,您已将其设置为类型object而过滤器中的所有字段都不存在于类型object In your flow.service.ts change the feild type to any. 在您的flow.service.ts将领域类型更改为任何。

filter: any;

使用名称过滤器初始化对象,例如:

filter = [];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM