-
Notifications
You must be signed in to change notification settings - Fork 7
type instability of the newValue change argument #8
Comments
Do you have a suggestion for something better? |
We could make But I imagine that would just cause a different set of complaints. |
Actually, I would prefer T[] just for consistency. I can imagine people not using types might complain that it is a bit harder, but newValue[0] is not too much harder than newValue. |
It's also two extra memory allocations on every change, when they aren't strictly needed (and why I originally went this route) |
On the other hand, if Typescript was smart enough to have type literals and the switch statement as a type guard, the problem would go away from the typescript perspective. That may be coming soon, at least for string literal typing. |
Yeah, I was also wondering about efficiency. |
|
and the same length as but I guess if you are spelling out |
See microsoft/TypeScript#1003 - const enum literals may solve the issue, in that typescript can be smarter about inferring types. |
The type instability of the newValue and oldValue arguments to an event is frustrating. It means that pretty much all event handlers need to cast newValue and oldValue (like https://github.com/jasongrout/jupyter-js-notebook/blob/4cf0e81d019f13bb8992c68b57cc25f4fb5f27bf/src/NotebookWidget.ts#L103)
The text was updated successfully, but these errors were encountered: