[@types/ember enhancement] - Cleanup around Ember.Object.{extend, reopen} #291
Labels
deferred [TS3]
Deferred until TS 3.0 is the minimum supported version
deferred
We have a specific reason for delaying implementation of this (but do plan to!)
enhancement
types:core
Something is wrong with the Ember type definitions
Uh oh!
There was an error while loading. Please reload this page.
Which package(s) does this enhancement pertain to?
Please write a user story for this feature
related conversation: https://discordapp.com/channels/480462759797063690/484421406659182603/489476577529167875
related code change:
mike-north/DefinitelyTyped@690bfed
The main part of this cleanup effort aims to do two things
1. Ensure that
Ember.Object.extend
andEmber.Object.reopen
return a type that accurately represents what these functions actually do.Conceptually, these functions essentially return the union of their input
In the above example, we're lying about the type of b. It will definitely be a number because we override the original property when defining B.
In terms of implementation the way to do this is to define a new utility type that's the union of B and anything on A that is not present on B
The TS implementation looks like
Then we can go and update types that currently look like this
to using
Mix<A,B>
instead ofA & B
There are many reasonable test cases that currently fail, and this change would allow them to pass, and provide us with more maintainable types, and more accurate and complete type safety across some of the most commonly used areas of Ember (i.e.,
get()
andset()
)2. Remove a workaround that was necessary in the TS2.x release series to properly handle things like
_super
and statics through an ineritance chain in a typed ember addonrelated issue: typed-ember/ember-typings#29)
There's a difficult-to-test (in the way we typically test ambient types) but reproducable issue involving extending from types through an addon in pre-3.0 versions of TypeScript.
Example:
My app uses
ember-resize
, which provides its own types that refer to@types/ember
.You can then try things like
and you'll get an error on each of the
a1
-a3
declarations. The message will have something to do with static properties likeprototype
. Tracking down the root cause for this reveals that the conflict/collsion is around the static properties of each class in the inheritance chain.The workaround @dwickern and @dfreeman figured out was to make the statics
Readonly<T>
in.extend
's return type.In TS 3 this is no longer necesary, and the types become more flexible by removing this workaround.
The text was updated successfully, but these errors were encountered: