https://stackoverflow.com/questions/33800497/check-if-an-object-implements-an-interface-at-runtime-with-typescript
Typescript interface defines data / object structure. However, types are used in typescript only in development and compile time. Type information is not in the compiled Javascript code.
Alternatives include:
- ts-interface-builder : tool to build runtime descriptors
- ts-interface-checker : to use the runtime descriptors to validate objects
- typescript-json-schema to convert interface to JSON schema and then use JSON schema validator (ajv)
- define type in JSON schema, then use .d.ts file generator (DTS generator) to compile typescript type definitions
- io-ts:
- define type with own type system similar to typescript
- then be provided with encoder / decoder/ type guard
- and looks VERY compatible with typescript ecosystem
Less popular solutions are also provided: