0
基本的に、私はオプションの引数は、特定の列挙型の値であり、鍵を持っていることを確実にする方法をしたい:typescriptを使用してオブジェクトキーをenums値に制限できますか?
//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() } });
私はインターフェイス/クラスの代わりに、列挙型を使用する場合、それは完璧に動作しますが、これは本当にあります列挙型(概念的には)...
私はこれらの行に沿って考えていました。情報をありがとう! – Lucas