I have a function that accepts an object as the only parameter. For example:
interface MyMap<T> {
[id: string]: T;
}
type Options = {
asObject: boolean,
other?: Function
};
function get(options: Options): any[];
function get(options: Options): MyMap<any>;
function get(options: Options): any[] | MyMap<any>;
function get(options: Options = {asObject: false, other: () => {}}): any[] | MyMap<any> {
if (options.asObject) return {} as MyMap<any>;
return [];
}
const result = get({asObject: true});
When the asObject value is true, I want to infer the type to MyMap. I know how to do it with simple boolean value, but how can I accomplish this with an object?