Closed
Description
TypeScript Version: 2.6.1
Code
enum Fruit {
APPLE = 'Apple',
}
enum Veggies {
CARROT = 'Carrot',
}
type FruitAndVeggies
= Fruit
& Veggies;
Requested behavior:
An intersection type of Fruit & Veggies
ie the following:
type FruitAndVeggies = 'Apple' & 'Carrot';
Actual behavior:
type FruitAndVeggies = never
Use Case
Writing a Vue application with Typescript and using Vuex. I have used enums to enforce type strictness on the names of the mutations, actions and getters similar to the following:
export enum MutationTypes {
SET_DRAWER_SHOWN = 'setDrawerShown',
}
const mutations = {
[MutationTypes.SET_DRAWER_SHOWN] (state: AppState) {
// ...
},
};
Doing it this way however prevents me from using the Mutations = Module1Mutations | Module2Mutations
type as an argument to commit mutations, if one of my <module>Mutations
enums is empty (due to commit(type: string)
. I have created a workaround, but this feature would be nice if other people are also interested in it. Also if anyone has an appropriate solution that I haven't though of suggestions are welcome 😁
Thanks for Typescript!