In the following snippet, Product is a Typescript interface. I would like to ensure every object in products adheres to that interface, but have no idea how. I've tried a few things like products<Product[]>: but nothing seems to work. I'm new to Typescript and would appreciate any help!
import * as faker from 'faker'
import { v4 as uuidv4 } from 'uuid'
import { Product } from './models/Product'
export default {
products: [
{
id: uuidv4(),
name: faker.commerce.product(),
description: faker.random.words(7),
cents: faker.commerce.price(300, 15000),
quantity: faker.random.number(15)
}
]
}
Edit:
Simpler example per request
interface Product {
id: string
name: string
quantity: string
}
export default {
products: [ // How to make sure all objects in this array adhere to the Product interface above?
{
id: 1,
name: 'Banana',
quantity: 10
}
]
}
products<Product[]>: {...}inline like that, but it seems I can't.