@doubleedesign/type-checker
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

type-checker

Provides the ability to check which TypeScript type(s) an object is anywhere in your code in a Node development environment.

Example setup

// tsconfig.json
{
    "compilerOptions": {
        "baseUrl": "./",
        "module": "esnext",
        "target": "esnext",
        "moduleResolution": "node",
        // ... more options as you need
    },
    "typechecker": {
        "types": ["Artist", "Album"], // names of the types you want to be able to check against 
        "locations": ["./types.ts"] // where the type definitions are located 
    }
}

Example usage

import { TypeChecker } from '@doubleedesign/type-checker';

const boss: Artist = { name: 'Bruce Springsteen' };
const type: string[] = TypeChecker.getType(boss); // ['Artist']

Notes

  • For performance reasons, this may not be production-ready. So far my main use of it has been for unit testing.
  • This only checks for matching object keys, not that the values are the correct type.

Roadmap/future goals

  • Make it check value types, not just key names.
  • Make it work in the browser.
  • Improve performance.

Readme

Keywords

Package Sidebar

Install

npm i @doubleedesign/type-checker

Weekly Downloads

0

Version

0.1.2

License

none

Unpacked Size

15.9 kB

Total Files

11

Last publish

Collaborators

  • doubleedesign