# @codexsoft/function-implements-interface

> Allows runtime-check that object implements an interface (missing functionality in TypeScript)

Latest version **1.0.5** (published 2019-10-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install @codexsoft/function-implements-interface
pnpm add @codexsoft/function-implements-interface
yarn add @codexsoft/function-implements-interface
bun add @codexsoft/function-implements-interface
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2019-10-04 |
| First published | 2019-10-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kozubskiy Dmitriy |
| Maintainers | codexsoft |
| Keywords | typescript, interface, implements, instanceof, runtime |

## Links

- npm: https://www.npmjs.com/package/@codexsoft/function-implements-interface
- Repository: https://github.com/codexsoft/function-implements-interface
- Homepage: https://github.com/codexsoft/function-implements-interface#readme
- Issues: https://github.com/codexsoft/function-implements-interface/issues
- npm.io page: https://npm.io/package/@codexsoft/function-implements-interface

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-10-04
- 1.0.4 — 2019-10-04
- 1.0.3 — 2019-10-04
- 1.0.2 — 2019-10-04
- 1.0.1 — 2019-10-04
- 1.0.0 — 2019-10-04

## README

# function-implements-interface

`npm install @codexsoft/function-implements-interface`

Allows runtime-check that object implements an interface (missing functionality in TypeScript)

```javascript
let actualObj = {x: 'asd', y: 42};
let expectedInterface = {x: 'string'};
implementsInterface(actualObj, expectedInterface);
// returns true
```

interface objects are regular javascript objects where values are expected types.

`x: "function"` will expect that x is function 

`x: "string"` will expect that x is string
 
`x: "number"` will expect that x is number
 
`x: "object"` will expect that x is object
 
`x: "array"` will expect that x is array

`x: ["number", "string"]` will expect that x is number OR string

`x: {y: "number", z: "string""}` will expect that x is object and implements provided interface structure (recursive)

note, that in js every array is object, but not every object is array.

for typescript 

```typescript
import {implementsInterface} from "@codexsoft/function-implements-interface";
 
// regular typescript interface
interface SomeInterface {
    x: string;
}

// interface structure object
let someInterface = {
    x: 'string',
}

let obj = {x: 'hello world'};
if (implementsInterface<SomeInterface>(obj, someInterface)) {
// typescript will know that obj IS SomeInterface
    console.log(obj.x); 
}
```

---
_Source: https://npm.io/package/@codexsoft/function-implements-interface · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
