typify-gen
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

Resume

Generates dynamic types in TypeScript

npm i typify-gen --save

const myArray: <any extends object>[] = [...];

const { objects } = typifyGen(myArray);

const myArrayTyped = objects;

// myArray has been typed using the union
// of properties given by the objects in the array

// if you set up the intersection generation, you will
// be warned that your optional properties will still be displayed
// by autocompletion due to TypeScript's behaviour, which cannot
// infer the dynamic generation

API

typifyGen<T>(objects: T, logic?: "union" | "intersection") => {

  objects : GenType[]

  isGenType : (val: object) => object is GenType

  isGenTypeInherited : (val: object) => boolean

  genTypeCoercion : (val: object, byDefault?: object) => GenType

  genTypeKeys : string[]

  genTypeOptionalKeys : string[]
}

Package Sidebar

Install

npm i typify-gen

Weekly Downloads

1

Version

1.5.2

License

MIT

Unpacked Size

13.9 kB

Total Files

6

Last publish

Collaborators

  • hupiat