fix: Mark prototype property of constructors as readonly#968
fix: Mark prototype property of constructors as readonly#968ExE-Boss wants to merge 2 commits intomicrosoft:mainfrom
prototype property of constructors as readonly#968Conversation
|
We think this is probably a bit too big of a change for its value, I agree that it better reflects reality (example below) but it's hard to gauge a potential breaks from something like this. |
I'm not sure I understand the reasoning here, your example looks like it will benefit from |
|
(But I guess some polyfill can legally assign things to |
|
Can we move this PR forward? |
|
We nowadays have better testing and hopefully the CI in microsoft/TypeScript side repo can catch potential breakage @orta was talking about on DefinitelyTyped. PR welcome (assuming one would also try the CI on TS repo too) |
|
Before doing this, you probably need to consider microsoft/TypeScript#58296 as it may become necessary to remove the |
|
Not sure what those some would be. Would that be because of compatibility issue with packages? |
|
No, it's because the PR would actually enforce that you can't assign an object with a readonly property to one that has the same property but mutable, and that relationship also applies to interfaces extending other interfaces. So, you can't inherit a mutable prototype and then mark it as readonly or vice versa. But, maybe it would work out to mark all prototypes as readonly, it just doesn't seem like that's the way things are going based on the discussions about the PR. |
This more closely matches runtime behaviour.
It also causes code that would try to re‑assign the
prototypeproperty of WebIDL constructors to have the error caught at compile time, rather than at run time.