Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albertarakelyan/is-object-typeof-interface
A simple package which returns true when object is type of some specific interface or type.
https://github.com/albertarakelyan/is-object-typeof-interface
interface objects package type typescript
Last synced: 26 days ago
JSON representation
A simple package which returns true when object is type of some specific interface or type.
- Host: GitHub
- URL: https://github.com/albertarakelyan/is-object-typeof-interface
- Owner: AlbertArakelyan
- Created: 2023-06-16T19:39:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-16T19:50:14.000Z (over 1 year ago)
- Last Synced: 2023-12-24T14:04:57.916Z (11 months ago)
- Topics: interface, objects, package, type, typescript
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-object-typeof-interface
> A simple package which returns `true` when object is type of some specific interface or type.This is my first package, hope it will be helpful. :heart:
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install is-object-typeof-interface
```## Usage
```ts
import isObjectTypeOfInterface from 'is-object-typeof-interface';interface IObj1 {
foo: string;
bar: number;
}interface IObj2 {
baz: boolean;
biz: string;
}const obj1: any = { foo: 'str', bar: 5 };
const obj2: any = { baz: true, biz: 'str' };const result1 = isObjectTypeOfInterface(obj1, 'foo');
const result2 = isObjectTypeOfInterface(obj2, 'baz');console.log('Result 1: ', result1); // true
console.log('Result 2: ', result2); // true
```## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/ALbert2504/is-object-typeof-interface/issues/new).Motivation
Receving an object from Redux store had two different types as the same component was rendering different datas, and I needed check what interface my object has to get correct property. After googling I found [this](https://stackoverflow.com/questions/14425568/interface-type-check-with-typescript) question and published this package, which will be extended in future.
### Author
**Albert Arakelyan**
* [LinkedIn Profile](https://www.linkedin.com/in/albert-arakelyan/)
* [GitHub Profile](https://github.com/ALbert2504)