I have two typescript types that I would like to combine into one generic type:
type WordTimestamps = {
timestamps: {start: number, end: number},
word: string
}
type SentenceTimestamps = {
timestamps: {start: number, end: number},
sentence: string
}
The only difference between them is the second key, so I want to come up with a single generic type which I imagine should be called as something like Timestamps<'word'> for the former and Timestamps<'sentence'> for the latter.
I can't seem to figure out how to do this. I've only come up with the code below, which doesn't do it.
type Timestamps<T> = {
timestamps: { start: number; end: number };
[key: T]: string;
};