Skip to content

Commit

Permalink
Merge pull request #432 from abraham/readme
Browse files Browse the repository at this point in the history
Document type guards
  • Loading branch information
abraham authored Feb 19, 2022
2 parents be55d41 + 852216c commit 136a041
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ class Thing {
}
```

Using included [type guards](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).

```ts
import { RemoteData } from '@abraham/remotedata';
import { Status } from 'twitter-d';
import { getState } from './state';

// Define what the RemoteData Failure and Success types will be.
type State = RemoteData<number, Status>;

const state: State = getState();
if (isSuccess(state)) {
// state is known to be of type Success<Status>
console.log(state.data.full_text);
}
```

# References

- [How Elm Slays a UI Antipattern](http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html)
Expand Down

0 comments on commit 136a041

Please sign in to comment.