0.1.8 • Published 1 year ago

@barelyhuman/typeable v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

typeable

a on-the-fly type generator for objects in node

Warning: This will not really work in a browser, it expects a filesystem

Installation

Install @barelyhuman/typeable with npm

  npm install @barelyhuman/typeable

What and Why

It's a generator for object interfaces. I have a project that I'm working on which has a ton of shared objects being defined during development, this makes it hard to keep track of what all was defined on the object.

Typescript has cross file inference but still doesn't help with dynamically defined properties so this helps generate a declarations file that stores all the properties added to the object. There's definite knick knacks that can be fixed.

Note: This is a subset requirement for one of my packages and might not be something you need for your day to day development. The generator's goal is to be able to generate types at runtime while in development.

Note: If the NODE_ENV is set to production, the type generator will not run.

Usage

const { createTypeable } = require('@barelyhuman/typeable')

/**
 * @type {import("./typeable").App}
 */

const app = createTypeable(
  {}, // an empty object or reference to an object to be read
  {
    outfile: 'typeable.d.ts', // output path for the generated declaration file
    rootInterfaceName: 'App', // the interface name to be generated for the above object.
  }
)

// add in properties, functions, methods, etc to the new typeable object.
app.property = {}
app.property.method = function () {}
// typeable.d.ts
export interface App {
  property: property
}

interface property {
  // generated generic functions right now
  method: (...args: any[]) => any
}

Caveats

  • Cannot handle kebab-case or spaced keys and will ignore them altogether
  • Cannot infer the type of arguments from a function

License

MIT

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago