I am trying to design an interface for postComments, it looks like this:
interface PostComments {
postId:{
id: string;
comment: string;
postId: string;
}[]
}
I want the compiler to give me an error when the postId's are not the same
the progress that I made so far is:
interface Comment<T> {
id: string;
comment: string;
postId: T
}
interface PostComments {
[postId:string]:Comment<PostComments.postId>[];
}
but unlucky me, typescript is not happy with the interface that I wrote, how can I throw a compile time exception for this? please let me know if someone have an idea about it.
=========================================================================
i want the comments object to look like:
comments = {
"abc123": [
{
id: "xyz098",
comment: "a sample comment",
postId: "abc123",
},
{
id: "xyz987",
comment: "another sample comment",
postId: "abc123",
},
],
"bcd123": [
{
id: "yxz098",
comment: "a new sample comment",
postId: "bcd123",
},
{
id: "yxz987",
comment: "another new sample comment",
postId: "bcd123",
},
]
}
postId in every array element of the corrosponding post