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

Inconsistent behavior a class not being readonly if it is inside a module #16579

Closed
webbiesdk opened this issue Jun 16, 2017 · 3 comments
Closed
Labels
Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@webbiesdk
Copy link

TypeScript Version: 2.3.4

Code

module Bar {
    export class Foo {
        bla = 123;
    }
}

class Foo {
    bla = 123;
}

Bar.Foo = Foo; // no error
Foo = Bar.Foo; // error: "Cannot assign to 'Foo' because it is not a variable.

Expected behavior:
Either both of the last two lines to report an error, or none of them.

Actual behavior:
It is only an error to replace a class, if it is not inside a module.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Jun 16, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.5 milestone Jun 16, 2017
@DanielRosenwasser
Copy link
Member

We should discuss what the "correct" behavior is.

@webbiesdk
Copy link
Author

webbiesdk commented Jun 18, 2017

Modules and functions inside modules have the same behavior.

I think the "correct" behavior should be to have an error in both cases, since it seems unlikely that a programmer intends to overwrite a class/module definition.
You can always cast to any if you really want to do it.

@ghost ghost added Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed Bug A bug in TypeScript labels Jul 29, 2017
@ghost
Copy link

ghost commented Jul 29, 2017

See #17502.

@ghost ghost closed this as completed Jul 29, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

2 participants