-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Function with properties type inferred only at top level #31972
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
Comments
This is the intended behavior - you can "declare" new properties "locally" with bare assignments, but you can't just tack on new properties anywhere |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Second look: Probably a bug. Moving the same code into a block shouldn't really affect it's validity, as is shown here. |
cc @sandersn there's some sort of check we have for top-level blocks, but not nested blocks, which seems quite unfortunate here. |
Check the binder in bindPropertyAssignment; it's where the most complex top-level check is, and is probably the culprit. I don't think there are any top-level checks in the checker, but I could be wrong. |
TypeScript Version: 3.5.1
Search Terms:
Code
Expected behavior:
I would expect the same behavior both inside and outside the block.
Actual behavior:
Assigning properties to a function at the top level is allowed, but not inside a block. Frankly, I'm impressed that the first example works at all. But I don't see why they would be different!
Playground Link: link
Related Issues:
The text was updated successfully, but these errors were encountered: