Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 z

example

```
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 true

console.log("is goldfish a fish? " + isA(goldfish, ["color"]));
//return true

console.log("is goldfish a fish? " + isA(goldfish, ["color", "name"]));
//return false
```