Skip to content

Commit

Permalink
Add isInstanceOf() next to getType() section (#48)
Browse files Browse the repository at this point in the history
* Add isInstanceOf() next to getType() section

* Update README.md

---------

Co-authored-by: Luca Ban <[email protected]>
  • Loading branch information
jcbhmr and mesqueeb authored May 31, 2023
1 parent 5895bc8 commit 9366f86
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ getType('') // returns 'String'
isType('', String) // returns true
```

If you just want to make sure your object _inherits_ from a particular class or
`toStringTag` value, you can use `isInstanceOf()` like this:

```js
import { isInstanceOf } from 'is-what'

isInstanceOf(new XMLHttpRequest(), "EventTarget")
// returns true
isInstanceOf(globalThis, ReadableStream)
// returns false
```

## TypeScript

is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users.
Expand Down

0 comments on commit 9366f86

Please sign in to comment.