hmenyus / node-calls-python

Call Python from NodeJS directly in-process without spawning processes
MIT License
252 stars 26 forks source link

Typescript types #20

Closed willfrew closed 2 years ago

willfrew commented 2 years ago

I was just using your package in a typescript project and needed to quickly write out some type definitions for it. I ended up not using them and didn't have time to submit a full PR but thought I'd ping them over in case you wanted to add typings to the package (or in case they would be helpful to others):

node-calls-python.d.ts:

declare module "node-calls-python" {
  // Opaque, unconstructable objects to pass around.
  export class PyModule {
    private _type: 'PyModule';
    private constructor() {}
  }
  export class PyObject {
    private _type: 'PyObject';
    private constructor() {}
  }

  export interface Interpreter {
    import: (filename: string) => Promise<PyModule>;
    create: (module: PyModule, className: string, ...args: any[]) => Promise<PyObject>;
    call: (module: PyModule | PyObject, functionName: string, ...args: any[]) => Promise<unknown>;
    callSync: (module: PyModule | PyObject, functionName: string, ...args: any[]) => unknown;
  }

  export const interpreter: Interpreter;
}
hmenyus commented 2 years ago

Thanks, added the d.ts file in master. Will be released in 1.7.0.