Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucereal/isa
A module to check if an object is a specific typescript interface using type guards
https://github.com/lucereal/isa
Last synced: 7 days ago
JSON representation
A module to check if an object is a specific typescript interface using type guards
- Host: GitHub
- URL: https://github.com/lucereal/isa
- Owner: lucereal
- Created: 2019-02-14T07:12:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T15:00:12.000Z (almost 6 years ago)
- Last Synced: 2024-11-14T08:31:10.856Z (2 months ago)
- Language: TypeScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# isA
check if an object is a certain type
```
isA(x: any, z: Array): boolean
```- T: typescript interface
- x: object to be checked against interface
- z: Array of strings that should be property names in the object
- return: true if `x is a T`, that is if x has all the properties listen in zexample
```
import { isA } from 'isa';interface fish{
color:string,
age:5
}let goldfish = {
color: "gold",
age: 44
}console.log("is goldfish a fish? " + isA(goldfish, ["color", "age"]));
//return trueconsole.log("is goldfish a fish? " + isA(goldfish, ["color"]));
//return trueconsole.log("is goldfish a fish? " + isA(goldfish, ["color", "name"]));
//return false
```