I have made a TypeScript class like this:
export class MyClassName {
id: number;
name: string;
data: /* JSON ARRAY */;
}
What I want to do is to cast the "data" property as a JSON array ( [JSON, JSON, JSON].... ).
I've tried the following:
export class MyClassName {
id: number;
name: string;
data: [key: any];
}
When serving the app using "ng serve" it gives this error message but the app still functions as intended:
ERROR in src/app/myclass.ts(4,14): error TS1005: ',' expected.
but when I'm trying to build it using "ng build --prod" it fails to build due to the same error message.
If its an array of stringified
JSON
, you can just usestring[]
. Else, you can use the following.
export class MyClassName {
id : number;
name : string;
data : {[key: string]: any}[];
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments