I have a class method which accepts a single argument as a string and returns an object which has the matching type property. This method is used to narrow a di
A little more verbose on the setup but we can achieve your desired API with type lookups:
interface Action {
type: string;
}
interface Actions {
[key: string]: Action;
}
interface ExampleAction extends Action {
type: 'Example';
example: true;
}
interface AnotherAction extends Action {
type: 'Another';
another: true;
}
type MyActions = {
Another: AnotherAction;
Example: ExampleAction;
};
declare class Example {
doSomething(key: K): T[K];
}
const items = new Example();
const result1 = items.doSomething('Example');
console.log(result1.example);