From a typed Object, is it possible to transform it into an interface in TypeScript?
I already read this QA here on StackOverflow, and don't think it fits well with the description I give in this Question.
Quick Example, this scenario where type Product is defined as type from a third-party TypeScript library.
# ProductFragmentOne is used to highligt possibility of composition(unions, etc)
type Product = ProductFragmentOne & { sku: string };
To integrate that product in our own system, it is already possible by extending(union) a type as in the following example:
export type ProductSchema = Product & {
name: string;
}
My question is:
- Is there a way for our
ProductSchemato be defined as aninterface, instead of using the types approach? Or is that even possible?
# Example of how the code may look
export interface ProductSchema{
name: string;
// do the magic to add Product properties here
}
Update: The reason for this approach is purely preference of interfaces over types. Also to make existing code keep its style, regardless of third party library adopted.
Thanks.