The JSDoc api says you can document objects like so:
{Object.<string, number>}
and document multiple type:
{(number|boolean)}
But if I try to specify an object that could have strings OR numbers as the key, it does not work. VSCode/JSDoc just reports the type as 'any'.
VSCode does not understand:
/**
* Object with string or number for keys
* @param {Object.<(string|number), any>} Container
*/
I've also tried this in @typedef
, or defining the key in it's own @typedef
to no effect.
Because I'm using &
to get an intersection
of types (like {Object.<string, any> & {'foo': number}}
I don't want to have to use the boolean or to say:
/**
* Object with string or number for keys
* @param {(Object.<string, any>|Object.<number, any>) & {'foo': number}} Container
*/
The type documented ends up looking something like:
type Container = ({
[x: string]: any;
} & {
'foo': number;
}) | ({
[x: number]: any;
} & {
'foo': number;
})
Which is needlessly verbose.
Is there way to document this with a more succinct output?