Get return type with reflect-metadata , when return type is Promise of something
It seems that this feature will not be supported in the near future.
As noted in #14971 (comment), reflection and runtime type serialization is outside the scope of the TypeScript project in the time being.
— Mohamed Hegazy (link)
Try to use Custom Method Decorator ?
/* Important Notes
- all type passed in the Decorator must be class
- interface & enum are not supported*/
(TypeScript)
export function ReturnType(type: any): MethodDecorator { return (target, propertyKey) => { Reflect.defineMetaData('YOUR_CUSTOM_KEY', type, target, propertyKey); }}// Somewhere in your code@ReturnType(Number)async function myFunc():Promise<number> { return await Promise.resolve(1234)}