Learning TypeScript syntax can be challenging, so it's recommended to try the code in TS Playground and experiment to gain a better understanding.
Here is the link to the Playground
Now let's revisit your code:
declare namespace Reflect {
function metadata(metadataKey: any, metadataValue: any): {
(target: Function): void;
(target: Object, targetKey: string | symbol): void;
};
}
const m = Reflect.metadata('test', 'test');
m(console.log); // TypeScript suggests m(target: Function): void
m({}, 'test'); // TypeScript suggests m(target: Object, targetKey: string | symbol): void
This situation involves argument overloading. From this, we can infer that the function signature of metadata is as follows:
- metadata will return a function (referred to as fn)
- fn can accept another function as an argument
- Or fn can accept an object (target) and either a string or symbol as additional arguments