You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Class declaration not checked for compatibility with Object.prototype #15453
I agree it's unsound, but it'd also be strange/annoying to effectively say (by the same argument) that e.g. const x = { toString: true }; is an illegal object literal that you simply cannot write. Sometimes you do want to do that and aren't going to dangerously alias by a supertype.
Hmm, yeah. I agree it's definitely sacrificing convenience for soundness. Not sure what the calculus is for making those tradeoffs for your team, so I'll trust the experts!
You're right to be surprised; It should be an error. I'm leaning toward making the literal itself an error (the strange/annoying solution). Object is different than in TS, I believe. It's a weird flavor of any that I don't particularly care for :/
I'm leaning toward making the literal itself an error
Not sure if Flow allows people to add things to the global type of all Objects (e.g. cute global-prototype-mutating libraries) but this might cause some weird interactions.
Yeah, we're inconsistent about what we check against Object.prototype (for now). If you take the stance that all object should be subtypes of the Object.prototype, things become concrete if inflexible.
It is to some extent, but I think our view up until this point has been that extends and implements enforce some guarantees about what declared type's shape will be (as opposed to intersections and unions which act a little more blindly - not always a bad thing though!).
Just thinking... if soundness is the goal, the only plausible fix is to disallow calls to things from Object.protoype. It's not going to be possible to detect this case:
For sure, and I don't think anyone is suggesting that soundness is binary 100% or 0% (when it comes to static analysis of JS, that is). It's all about trade-offs, and I was just hoping to clarify what kind of trade-off was being made here, and hopefully to get a sense of what the calculus is for deciding those trade-offs.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
RyanCavanaugh commentedon Apr 28, 2017
I agree it's unsound, but it'd also be strange/annoying to effectively say (by the same argument) that e.g.
const x = { toString: true };is an illegal object literal that you simply cannot write. Sometimes you do want to do that and aren't going to dangerously alias by a supertype.samwgoldman commentedon Apr 28, 2017
Hmm, yeah. I agree it's definitely sacrificing convenience for soundness. Not sure what the calculus is for making those tradeoffs for your team, so I'll trust the experts!
RyanCavanaugh commentedon Apr 28, 2017
I was vaguely surprised that this wasn't an error in Flow (it is in TS):
Does
Objectwork differently?samwgoldman commentedon Apr 28, 2017
You're right to be surprised; It should be an error. I'm leaning toward making the literal itself an error (the strange/annoying solution).
Objectis different than in TS, I believe. It's a weird flavor ofanythat I don't particularly care for :/RyanCavanaugh commentedon Apr 28, 2017
Just playing with it more... interesting behavior! It's hard to reckon what the right behavior is.
Not sure if Flow allows people to add things to the global type of all
Objects (e.g. cute global-prototype-mutating libraries) but this might cause some weird interactions.samwgoldman commentedon Apr 28, 2017
Yeah, we're inconsistent about what we check against Object.prototype (for now). If you take the stance that all object should be subtypes of the Object.prototype, things become concrete if inflexible.
vkurchatkin commentedon May 2, 2017
It's a bit weird though that
is an error and
is not, while semantically this is exactly the same thing.
DanielRosenwasser commentedon May 2, 2017
It is to some extent, but I think our view up until this point has been that
extendsandimplementsenforce some guarantees about what declared type's shape will be (as opposed to intersections and unions which act a little more blindly - not always a bad thing though!).RyanCavanaugh commentedon May 2, 2017
Just thinking... if soundness is the goal, the only plausible fix is to disallow calls to things from
Object.protoype. It's not going to be possible to detect this case:samwgoldman commentedon May 2, 2017
For sure, and I don't think anyone is suggesting that soundness is binary 100% or 0% (when it comes to static analysis of JS, that is). It's all about trade-offs, and I was just hoping to clarify what kind of trade-off was being made here, and hopefully to get a sense of what the calculus is for deciding those trade-offs.
mhegazy commentedon May 19, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.