'TypeScript: Define type as any of interface keys

I am developing a React/TypeScript project and I am facing the following situation:

I have an interface Actions which has many keys.

interface Actions { toggle: { type: 'toggle', }, alert: { type: 'alert', payload: string } }`

I want to define a type Action which shall assume any of Actions subtypes and only those.

How can that be done?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source