Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick and dirty typescript definitions #7

Closed
wants to merge 0 commits into from

Conversation

sparebytes
Copy link

@sparebytes sparebytes commented Dec 29, 2016

See #6

99% of the defintions were generated using the tsd-jsdoc module and executing:
jsdoc -t node_modules/tsd-jsdoc -r ./node_modules/pg-structure/lib

I am using these definitions in a personal project and can confirm that they work for my needs.

@ozum
Copy link
Owner

ozum commented Dec 29, 2016

I will include this, but I wonder is there anyway to automate rest 1% to make it scriptable for future updates. Definitions must be in sync with future updates right?

@sparebytes
Copy link
Author

sparebytes commented Dec 29, 2016

Agreed, that would be ideal. Let me explain that 1%. Most of it had to do with the @type declarations:

  • Strip declare from the begninng of any line that had it
  • Change Array.<string> to Array<string> or string[]
  • Change Map.<xxx> to Map<string, xxx> or Map<any, xxx>
  • Change Set.<xxx> to Set<xxx>
  • Change Promise.<xxx> to Promise<xxx>
  • Change WeakMap to WeakMap<any, any>
  • Change pg#client to pg.Client
  • Delete declare class Map { ... } and everything inside
  • Delete module pgStructure but leave what was inside in-tact
  • Prepend:
<reference types="pg" />
import * as pg from 'pg';

declare namespace pgStructure {

    type relationType = {};
    type constraintType = {};

  • append
}

declare function pgStructure(connection: pg.Client|pgStructure.IpgOptions, options?: {}): Promise<pgStructure.Db>;
declare function pgStructure(connection: pg.Client|pgStructure.IpgOptions, schemas?: string[]|string, options?: {}): Promise<pgStructure.Db>;

export = pgStructure;

So the biggest issues is that:

  • I was having issues with relationType and constraintType so I just declared them ambiguously.
  • The jsdoc cli tool wasn't able to produce type definitions for the main function which is why declare function pgStructure(...) was manually appended to the end.

@ozum
Copy link
Owner

ozum commented Jan 5, 2017

Could you write a simple javascript code to do this transformations and a few tests. I will add them to build workflow, and all future versions would have automatically up to date definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants