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

Object strict literal assigment checking is omitted for the empty type #4463

Closed
zpdDG4gta8XKpMCd opened this issue Aug 26, 2015 · 6 comments
Closed
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@zpdDG4gta8XKpMCd
Copy link

in #3823

interface A {
}
var a : A = { // valid code, but expected a problem in 1.6, since x, y, z don't belong to A 
    x: 1,
    y: 2,
    z: 3
};
@danquirk
Copy link
Member

Ryan had proposed a rule that would error here if A at least had some optional members, but not if it was empty. I'm not sure what the rationale was for not erroring against empty types as well: #3842

@RyanCavanaugh RyanCavanaugh added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Aug 26, 2015
@RyanCavanaugh
Copy link
Member

Lots of people use {} in place of any because they don't want accidental anys creeping in, but still want something that's assignable from anything. Erroring on object literals assigned to {} is kind of pointless because, if we did, there would be nothing valid you could have written -- if you really wanted a type that couldn't be assigned from any non-null/undefined value, void is there.

@zpdDG4gta8XKpMCd
Copy link
Author

Are values of void now officially a part of the language? Thought they were leaving.

@RyanCavanaugh
Copy link
Member

The void type isn't going anywhere. The only thing we've been warning people of using the crazy number|void thing to fake non-nullability.

@zpdDG4gta8XKpMCd
Copy link
Author

Can's say I see your point:

The void type isn't going anywhere.

Fine, since it's just a type let's keep it. I was talking about values of type void which sort of don't make sense since void by definition represents a lack of value. The only type that doesn't have a value yet is assignable from null and undefined (what might this mean?).

warning people of using the crazy number|void thing

Why would you warn? With all what's above number|void seems 100% legit (void is just another type that, hm, has values, remember?). Although I agree as far as making sense it fails, just like the idea of a legit value of void does.

thing to fake non-nullability

Business sees value in it and wants it. I would not call it faking unless proven otherwise. If number|void gives hard feelings how about a memberless enum?

const enum Nothing {}

Ugh, Nothing | number don't play nice together, dang, lets go back to void.

@zpdDG4gta8XKpMCd
Copy link
Author

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

3 participants