blessed-contrib icon indicating copy to clipboard operation
blessed-contrib copied to clipboard

Typedefinitions

Open bradleat opened this issue 7 years ago • 8 comments

Are there any plans to add typescript type definition to this great library?

bradleat avatar Apr 04 '17 21:04 bradleat

This is a good idea, I don't have time to implement this now but would happily accept a PR.

yaronn avatar Apr 05 '17 20:04 yaronn

Any thoughts on how to do it? Just add the declarations file or upgrade the project to typescript?

bradleat avatar Apr 05 '17 22:04 bradleat

I have not done it before so not sure what are the implications for each options. Does one of them force every library user to use typescript? Are they both backward compatible for all consumers?

yaronn avatar Apr 06 '17 08:04 yaronn

If you compile the project to JavaScript before publishing and only publish the js files nobody else has to use TypeScript. For compiling before publishing you could use prepublish under scripts in package.json. This way everything is compiled before publishing. During this process, you also could generate the TypeScript .d.ts files. The creating of .d.ts files is a simple setting in the configs from TypeScript. You also have to add the JavaScript output folder under files in the package.json

This way everybody can use the package, TypeScript or JavaScript.

lholznagel avatar Apr 24 '17 09:04 lholznagel

None of them force the user to use TypeScript.

If we rewrite the blessed-contrib in TypeScript, we will do a tsc to compile TypeScript into JavaScript before publishing to NPM, and every user will continue to use JavaScript and without noticed any changes.

And for TypeScript users, we can benefit from the d.ts definition files.

I just have a look into the lib source, I'll vote for rewrite the library to TypeScript, if possible. Because that will always keep the definitions file sync with the source code.

huan avatar Aug 20 '17 08:08 huan

I play a little with the type definition today, it should look like this:

// index.d.ts
import {
  widget,
  Widgets,
}             from 'blessed'

declare namespace BlessedContrib {

  export interface GridOptions {
    rows: number,
    cols: number,
    screen: Widgets.Node,
  }

  export class Grid {
    constructor(options: GridOptions)

    set<T>(
      row: number,
      col: number,
      rowSpan: number,
      colSpan: number,
      widget: T,
      options?: Widgets.BoxOptions
              | Widgets.FileManagerOptions
              | Widgets.ImageOptions
              | any,
    ): T
  }

  export class tree extends Widgets.BoxElement {}

}

export = BlessedContrib

In order to get started, I'd like to suggest we just put an index.d.ts with a declare any for blessed-contrib, then we could do the follow import in TypeScript:

import * as contrib from 'blessed-contrib'

Will do a pull request to enable it.

huan avatar Aug 29 '17 02:08 huan

i made a definition file that covers most of the library. #127

RobinRadic avatar Sep 24 '17 05:09 RobinRadic

Awesome, good job @RobinRadic !

huan avatar Sep 24 '17 06:09 huan