Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to correctly obtain the type of return value after the decorator #59060

Closed
1 task done
XDUyhfu opened this issue Jun 28, 2024 · 2 comments
Closed
1 task done

How to correctly obtain the type of return value after the decorator #59060

XDUyhfu opened this issue Jun 28, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@XDUyhfu
Copy link

XDUyhfu commented Jun 28, 2024

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

import { Observable, of } from "rxjs";
const observable = (target: any, context: ClassMethodDecoratorContext) => function (...args: unknown[]): Observable<string> {
	return of<string>(target.apply(this, args))
}
class Test {
	@observable
	print() {
		return "print test";
	}
}
new Test().print().subscribe(console.log)

What I expect is that after using the observable decorator, the type of the return value of my method can be successfully deduced into Observable instead of the original string type.

what should i do

@MartinJohns
Copy link
Contributor

Decorators can't currently change the types of whatever they're applied to. This would first require #4881 to be supported.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Jul 1, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants