AlexeyBoiko / DgrmJS

Dgrm.net - flowchart editor. Works on desktop, phone and tablet. Has no dependency. Pure JavaScript.
https://dgrm.net
Apache License 2.0
906 stars 83 forks source link

Types #8

Closed tbo47 closed 2 years ago

tbo47 commented 2 years ago

It would be nice to have the types in the published package in npmjs. For developers using typescript instead of javascript.

In this pull-request I only migrate src/diagram/diagram.js to a syntax that typescript understands.

Let me know if you like this approach.

tbo47 commented 2 years ago

or maybe just switching to typescript instead of javascript?

AlexeyBoiko commented 2 years ago

Thanks for suggest.

It would be nice to have the types in the published package in npmjs.

Agree. I have to add types to npm package.

Public diagram interface is here: https://github.com/AlexeyBoiko/DgrmJS/blob/main/src/diagram/diagram-public-types.ts Types in diagram-public-types.ts must be the only types developer need to use DgrmJS.

The problem: diagram-public-types.ts depends on some types from presenter layer. It is needed to remove this dependence. Then I'll add diagram-public-types.ts to npm package.

For developers using typescript instead of javascript

Not only TypeScript developers use types. JavaScript developers olso use types. Types is used for creating DgrmJs.

TypeScript notations can be used along with JSDoc. https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html

switching to typescript instead of javascript?

JavaScript with JSDoc and TypeScript notations give the developer the same tooling:

I don't see why to use TypeScript. Pros of not using the TypeScript compiler:

Blog post with more information

tbo47 commented 2 years ago

that makes sense

AlexeyBoiko commented 2 years ago

Now all public types in diagram-public-types.ts.

You can build DgrmJS library to single js-file: npm run build-dgrm-npm

Singls js file will be in folder \dist\diagram-npm-package

Include this file to your typescript app. And use types from diagram-public-types.ts.