Reputation: 61
Is it possible to use key in Type
two times in a type?
For example:
type UnionTypeOne = '1' | '2'
type UnionTypeTwo = '3' | '4'
export type MyTime = {
[key in UnionTypeOne]?: {
[name: string]: boolean
}
[key in UnionTypeTwo]: boolean
}
Right now the compilation fails because the second ([key in UnionTypeTwo]: boolean
) is not allowed.
Upvotes: 1
Views: 93
Reputation: 887275
Use intersection types:
export type MyTime = {
[key in UnionTypeOne]?: {
[name: string]: boolean
}
} & {
[key in UnionTypeTwo]: boolean
};
Upvotes: 3