admin管理员组

文章数量:1303335

I have a class named Condition:

export class Condition{
    name: string;
    date: string;
    link: string;
}

And a function named search that makes http get requests:

public search(params: string): Observable<json[]> {
    let queryString = this.serverUrl + params;

     return this.http.get(queryString)
                     .map((res:Response) => res.json())
                     .catch((error:any) => Observable.throw(error.json().error || 'Server error'));

 } 

And I get an object to get conditions with specific properties from it. It has absolutely an object array in its entry attribute:

this.search(`Condition?patient=Patient/107795`).subscribe(data => {
    var conditionArray = data.entry;       // data.entry is absolutely an ARRAY
    for(var condition of conditionArray){
        conditions.push({    //conditions is a Condition[]
            name: condition.resource.code.coding[0].display,
            date: condition.resource.dateRecorded,
            link: "condition/" + condition.resource.id
        });
    }
    } , err => { console.log(err); } );

I was started these project before I wrote these code with start script:

"scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",

And the project was working as I wanted and no error on the console. However, when I stopped it and started again with the start script, it gives this error:

error TS2339: Property 'entry' does not exist on type 'any[]'.

Do you know what is wrong with it and how can I fix it?

I have a class named Condition:

export class Condition{
    name: string;
    date: string;
    link: string;
}

And a function named search that makes http get requests:

public search(params: string): Observable<json[]> {
    let queryString = this.serverUrl + params;

     return this.http.get(queryString)
                     .map((res:Response) => res.json())
                     .catch((error:any) => Observable.throw(error.json().error || 'Server error'));

 } 

And I get an object to get conditions with specific properties from it. It has absolutely an object array in its entry attribute:

this.search(`Condition?patient=Patient/107795`).subscribe(data => {
    var conditionArray = data.entry;       // data.entry is absolutely an ARRAY
    for(var condition of conditionArray){
        conditions.push({    //conditions is a Condition[]
            name: condition.resource.code.coding[0].display,
            date: condition.resource.dateRecorded,
            link: "condition/" + condition.resource.id
        });
    }
    } , err => { console.log(err); } );

I was started these project before I wrote these code with start script:

"scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",

And the project was working as I wanted and no error on the console. However, when I stopped it and started again with the start script, it gives this error:

error TS2339: Property 'entry' does not exist on type 'any[]'.

Do you know what is wrong with it and how can I fix it?

Share Improve this question asked Sep 7, 2016 at 7:46 Bünyamin SarıgülBünyamin Sarıgül 3,0914 gold badges34 silver badges56 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Your search method should probably return an object, not an array. Declare it as follows:

public search(params: string): Observable<any> {

Use any unless you have a type describing the result, if so, you may use that instead.

本文标签: javascriptAngular2 Property does not exist on type 39any39 (JSON)Stack Overflow