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
Docs: Decorators for class decorator needs to either be explicit about the type or note that new interface isn't inferred #443
Comments
I wound up here because I encountered this issue IRL - the example on the website led me to misunderstand the capabilities of the class decorator. Agree this example should be corrected so that it doesn't imply that decorators can define new properties on the object since that is not exactly the case right now (at least not in a way that typescript's compiler is happy about). |
Bumping this issue, as the docs continue to suggest that class decorators can reshape the target in a TypeScript-aware way. Given the number of related GitHub issues / StackOverflow questions, there seems to be a lot of avoidable wheel-spinning if the documentation were clearer on this point. I would suggest a new "NOTE" along the lines of:
Likewise, it may be best to remove the following line from the code example, as TypeScript will be unaware of
|
Page URL: https://www.typescriptlang.org/docs/handbook/decorators.html
Issue:
a.newProperty errors because
a
isn't inferred to havenewProperty
from theclassDecorator
.Recommended Fix: Either explicitly add the type in the code sample, or state in the docs
re microsoft/TypeScript#4881
The text was updated successfully, but these errors were encountered: