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
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;
}
(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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With