Combining Types
Is there a way to create a single type definition that incorporates the attributes of two separate types?
type BlogPost = {
title: string
image: {
src: string
width: number
height: number
}
content: string
}
type BlogPostDetails {
[detail: string]: string
}
In essence, I want blog posts to include a title, image, and content, as well as other details that are strings.
Challenge
Unfortunately, every attempt to merge these types has resulted in an error.
Property 'image' is incompatible with index signature.
Type 'image' is not assignable to type 'string'.
I've experimented with various approaches, such as:
type Post = BlogPost & BlogPostDetails
type Post = BlogPost & Record<string, string>
type Post = {
title: string
image: {
src: string
width: number
height: number
}
content: string
[detail: string]: string
}
Any thoughts or suggestions?