type UnionType = { type: 'Empty' } | { type: 'Data', value: number };
const App: Component = () => {
const [state, setState] = createSignal<UnionType>({ type: 'Empty' });
return <>
<p>{JSON.stringify(state())}</p>
<button onClick={_ => setState({ type: 'Data', value: 123 })}>Set</button>
<Switch fallback={<div>Fallback</div>}>
<Match when={state().type = 'Empty'}>
<div>Type is 'Empty'</div>
</Match>
<Match when={state().type === 'Data'}>
<div>Type is 'Data': data={state().value}</div> // <-- 'value' does not exist...
</Match>
</Switch>
</>
};
type UnionType = { type: 'Empty' } | { type: 'Data', value: number };
const App: Component = () => {
const [state, setState] = createSignal<UnionType>({ type: 'Empty' });
return <>
<p>{JSON.stringify(state())}</p>
<button onClick={_ => setState({ type: 'Data', value: 123 })}>Set</button>
<Switch fallback={<div>Fallback</div>}>
<Match when={state().type = 'Empty'}>
<div>Type is 'Empty'</div>
</Match>
<Match when={state().type === 'Data'}>
<div>Type is 'Data': data={state().value}</div> // <-- 'value' does not exist...
</Match>
</Switch>
</>
};