These are the definitions for two basic types:
type AudioData = {
rate: number;
codec: string;
duration: number;
};
type VideoData = {
width: number;
height: number;
codec: string;
duration: number;
};
Next, I need to create a MediaInfo type:
type MediaInfo = {
type: 'audio';
data: AudioData;
} | {
type: 'video';
data: VideoData
}
Typically, this approach works for me.
However, in certain scenarios - such as defining a field in a database using typeorm - I cannot utilize the |
symbol and instead require a structured definition like this:
type MediaInfo = {
type: 'audio' | 'video';
data: AudioData | VideoData;
}
Nonetheless, I understand that this method is somewhat ambiguous.
Therefore, my inquiry involves exploring how to define MediaInfo
more precisely without relying on the |
symbol technique previously employed.