I'm trying to define a mock array of objects in Typescript 2.3.3 (Angular 4), but I'm getting errors.
My main data class is defined in a file called invoice-config.ts:
import {CustomerVariant} from './customer-variant'
export class InvoiceConfig {
customerName: string;
customerVariants: CustomerVariant[];
}
These are the contents of customer-variant.ts:
export class CustomerVariant {
id: string;
templates: string[];
}
Now, I would like to create a mock array of InvoiceConfig objects in a file called mock-invoice-configs.ts. I've tried with this file:
import { InvoiceConfig } from './invoice-config';
export const INVOICE_CONFIGS: InvoiceConfig[] = [
{
customerName: "CUSTOMER1",
customerVariants = [
{
id: "A9",
templates = [
"default"
]
}
]
},
{
customerName: "CUSTOMER2",
customerVariants = [
{
id: "A3",
templates = [
"default"
]
}
]
}
]
But it produces errors:
ERROR in /home/myuser/client-app/src/app/mock-invoice-configs.ts (7,5): Cannot find name 'customerVariants'.
ERROR in /home/myuser/client-app/src/app/mock-invoice-configs.ts (7,22): '=' can only be used in an object literal property inside a destructuring assignment.
ERROR in /home/myuser/client-app/src/app/mock-invoice-configs.ts (19,5): Cannot find name 'customerVariants'.
ERROR in /home/myuser/client-app/src/app/mock-invoice-configs.ts (19,22): '=' can only be used in an object literal property inside a destructuring assignment.
I don't understand why it cannot find 'customerVariants' (is one of the properties of the InvoiceConfig class?). And how can I define an array of nested objects (customerVariants) without using '=' ?