I've been exploring ways to create a type-alias with properties like "answer" that I came across in this post by another user (Typescript interface optional properties depending on other property). Here's an example:
type Sample = {
key1: true,
key2?: string,
key3: number
} | {
key1: false,
key2?: string,
key3?: never
}
Now, if the dependent properties are nested inside (meaning both key2 and key3 depend on key1, where key3 only exists when key2 is true), how would one go about defining it? Could it look something like this:
type Sample = {
key1: {
key2?: true,
key3: number
}
} | {
key1: {
key2?: false,
key3?: never
}
}