I have a typescript interface like so:
interface DataSku {
fields: {
sku: string;
}
}
interface PostProduct {
fields: {
title: string;
skus: DataSku[];
}
}
Now I want to extend the Product interface so that each object in the skus array has an extra field. So I tried this:
interface Sku extends DataSku {
stripe: Stripe.skus.ISku;
}
interface Product extends PostProduct {
fields: PostProduct['fields'] & {
skus: Sku[];
}
}
In my code, I try a loop like so:
(product as Product).fields.skus.forEach(sku => console.log(sku.stripe));
This throws the following Typescript error:
Property 'stripe' does not exist on type 'DataSku'.
Have I extended the interface wrong? The console does output my stripe object as expected, so it's just Typescript that isn't happy with the definition.