-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
JS: properties on class and function declarations are not type checked #16239
Comments
Interestingly, the expected/missing errors do appear when the example is wrapped in a block: {
class Foo {}
Foo.bar = 1; // error
const Foo2 = () => {};
Foo2.bar = 1; // error
function FooBar() {}
FooBar.bar = 1; // error
} |
We're intentionally lax about this because there's no such thing as namespace merging (i.e. a function/class/namespace followed by a namespace) in JS. Tacking properties onto values is pretty common for JS users, so I believe we allow it for top-level declarations. As a matter of fact, this is something we're considering in TS itself. Check out #15868. |
Actually, the second part about only doing this for top-level declarations is not true - we should not issue an error even in the block scope. You'll see the error go away if you move the statements into a function body. @mhegazy mentioned that that should be a bug. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.3.4
Code
This errors is TS files, but not in JS files where
checkJs
is enabled.The text was updated successfully, but these errors were encountered: