Essentially, I want a way to ensure that an options argument has keys which are the values of a specific enum:
//enum Mode { Foo, Bar };
interface Mode { Foo: number, Bar: number }
interface View {
text: string;
};
class FooView implements View {
text = 'foo';
}
class BarView implements View {
text = 'bar';
}
function initialize(options: { mode: {[P in keyof Mode]?: View} }) {
let mode: View = options.mode.Foo;
}
initialize({ mode: { Bar: new FooView() } });
It works perfectly if I use an interface/class instead of enum, but this is truly an enum (conceptually)...
See this playground