Consider the following code snippet:
type Action = {
type: string;
data: /* need help here */;
};
// data is a string here
const action1: Action = {
type: 'foo',
data: 'bar'
};
// data is an object here
const action2: Action = {
type: 'complex',
data: {
first: 'John',
last: 'Doe'
}
};
// data is not defined here
const action3: Action = {
type: 'undef'
};
// and so on, the point is data can be anything
I am looking for a way in Typescript to set the type of data
dynamically based on the assigned value, without using any to retain editor's intellisense support. Is this possible in Typescript?