Let's be type-safer!
This is a wholly backwards-compatible change, which just adds one new feature and improves some docs.
⭐ Added
TrackedAsyncData now has the ability to use TypeScript’s type-narrowing functionality via the .isPending, .isResolved, and .isRejected (#2) checks:
import TrackedAsyncData from 'ember-async-data/tracked-async-data';
let data = new TrackedAsyncData(Promise.resolve('string'));
if (data.isPending) {
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // null (and a warning for accessing in an invalid state!)
} else if (data.isResolved) {
data.value; // string
data.error; // null (and a warning for accessing in an invalid state!)
} else if (data.isRejected) {
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // unknown
}(Remember that the null fallbacks for .value and .error will be removed in a future version which drops support for Ember Classic computed properties.)