Skip to content

Commit

Permalink
Document type guards
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham committed Feb 19, 2022
1 parent be55d41 commit 852216c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
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 852216c

Please sign in to comment.