Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS1131: Property or signature expected and error TS1005: ';' expected

Encountered this error while using Angular 8 and Typescript version 3.4.5 Trying to create a interface class in Angular like below:

 export interface Test {
    id: string;
    created-date: number;
    import-by: string;
 }

Error: created-date: number; error TS1128: Declaration or statement expected. created-date: number; error TS1005: ';' expected. import-by: string; error TS1128: Declaration or statement expected. import-by: string; error TS1005: ';' expected.

How to handle this when the json response from java back-end provides jsonProperty with dash and not camel-case

like image 528
mitha.s Avatar asked Jul 30 '19 13:07

mitha.s


2 Answers

If your property identifier contains - you need to put the property name in quotes ('' or ""):

 export interface Test {
    id: string;
    'created-date': number;
    'import-by': string;
 }

like image 89
Titian Cernicova-Dragomir Avatar answered Sep 24 '22 04:09

Titian Cernicova-Dragomir


(This answer is irrelevant to the issue above, but this could be helpful as the explanation could be relevant to the issue below)

One thing that might be helpful is that one cannot add an exclamation point on a property if the class itself already has an exclamation point after it. ! means it cannot be null or undefined. Still learning TS and the explanation was very vague.

Wrong:

export class Hello {
    info!: {
        num!: number; // Will complain about 'Property or signature expected.'
    }
}

Right: (Take out the ! mark in the 'num' property)

export class Hello {
    info!: {
        num: number;
    }
}
like image 38
beeeliu Avatar answered Sep 25 '22 04:09

beeeliu