I have a situation of nested types and what I would like to achieve is to have a specified property based on another property's value.
In the HTML I cycle the response of an API and, based on the type value received, I would like to have a different option value.
For example: if I receive a response where type is 'articles' I would like to have OptionArticles as ChatOptions.
Is there a solution for this?
This is the code:
export interface ChatMessage {
status: string;
query: string;
step: string;
richResponse: boolean;
payload: ChatPayload;
sessionId?: number;
}
interface ChatPayload {
type: ChatTypes;
options: ChatOptions;
confidence?: number;
gotAllParams?: boolean;
}
type ChatTypes = 'text' | 'date' | 'articles' | 'params';
type ChatOptions = OptionText | OptionArticles | OptionParams;
interface OptionText {
type: 'text' | 'date';
text: string[];
}
interface OptionArticles {
type: 'articles';
prefilled: Values[];
possible: Values[];
}
interface OptionParams {
type: 'params';
params: FineParams;
}
Thanks.