Skip to content

Let's be type-safer!

Choose a tag to compare

@chriskrycho chriskrycho released this 27 Mar 23:06
· 1183 commits to main since this release
bd766a4

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.)