blessed-contrib
blessed-contrib copied to clipboard
Typedefinitions
Are there any plans to add typescript type definition to this great library?
This is a good idea, I don't have time to implement this now but would happily accept a PR.
Any thoughts on how to do it? Just add the declarations file or upgrade the project to typescript?
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?
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.
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.
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.
i made a definition file that covers most of the library. #127
Awesome, good job @RobinRadic !