-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
empty class acts as "any" type: by design or bug? #5451
Comments
Yes. Note that the empty type does not behave as var e: Empty, f: Foo;
f = e; // Error TypeScript uses a structural type system, see also: |
I'm using typescript in an educational situation and would find useful to have a stricter mode that doesn't allow this special case. Is there any way to disable this? I found a work-around : adding a dummy private member makes not empty (obviously).
I use '_' instead of 'dummy' in my lib (empty File class, it's really just a handle for the user, no attributes or methods) but you get the idea. |
There isn't a way to disable this behavior using a flag or other setting. Adding a member to each class is the best solution. |
Is adding one an option or is it too tied to the type system? I haven't read the type system docs you provided above, yet. |
This isn't something we'd add an option for. It's a structural type system, so empty types are equivalent by definition. |
The following typechecks fine:
This also compiles
Is this by design?
The text was updated successfully, but these errors were encountered: