cornerstonejs / cornerstoneTools

A framework for tools built on top of Cornerstone.
https://tools.cornerstonejs.org/
MIT License
577 stars 452 forks source link

type definitions ? #1021

Open hiddentn opened 5 years ago

hiddentn commented 5 years ago

Hi guys , thank you your great work

do you guys provide type definitions for the library ? i think providing them would go a long way in making this library more usable

dannyrb commented 5 years ago

@TheHidden1, we do not, but only because we're mostly volunteers with limited time/resources. We would be more than happy to accept type definitions, or guidance on/PRs for a gradual transition to TypeScript for core library code.

swederik commented 5 years ago

Related: https://github.com/cornerstonejs/cornerstone/issues/336

People seem to be developing the definitions themselves but for whatever reason nobody has seen fit to contribute them back.

dannyrb commented 5 years ago

@talkdirty and @jussimattila is this something either of you have made progress on and would be interested in sharing with the community? If we can reach a critical mass here, it should relieve some burden on your individual teams to maintain these typings separately.

jussimattila commented 5 years ago

Sorry for the delayed reply, I missed the notification. We're still running on a really old version of cornerstone, using the very crude typings I wrote some years ago. We are planning to rewrite parts of our app using the latest cornerstone release and it would be a good time to work on the typings as well. I'm hoping to start this process within the next couple of months.

We'd be happy to share anything we do in this space and collaborate with others. We only use a limited set of features from cornerstone and are not experts in generating type definitions, so any help with that work would be great. I'm afraid that the typings we have/will create on our own won't be quite as extensive (or good quality) as a library user would normally expect.

georggrab commented 5 years ago

I actually was looking into this just yesterday and was hoping to find a cheap solution how to generate definitions for cornerstone. I tried using dts-gen but eventually gave up on it because it doesn't work with browser modules too well (more tailored to node libraries I guess). A more promising option seemed to be leveraging the existing jsdoc documentation in cornerstone to generate the typings using the a tsd template for jsdoc. I was actually able to produce some typings for cornerstone with this but they are quite horrendous, partly because the jsdoc seems incorrect in some places and also because jsdoc doesn't cope with the default export of anonymous functions that is used basically everywhere in cornerstone too well. I attached the generated typings (beware, these are not actually usable just yet). Here is how I produced them:

~/cornerstone $ npm i -D tsd-jsdoc jsdoc-export-default-interop
~/cornerstone $ npx jsdoc -t node_modules/tsd-jsdoc/dist -c jsdoc.json -r src/

Where jsdoc.json is

{
    "tags": {
        "allowUnknownTags": true
    },
    "source": {
        "includePattern": ".+\\.js(doc|x)?$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "plugins": ["node_modules/jsdoc-export-default-interop/dist/index"],
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": false,
        "default": {
            "outputSourceFiles": true
        }
    }
}

You'll see there are quite a couple of warnings generated we would have to fix with the jsdoc in cornerstone if we would continue this way.

Of course the alternative would be to hand-write typings (probably we would have to do this with the jsdoc approach too though, unless we get it to produce perfect typings), but the question is how do we maintain and test them for future versions of cornerstone.

Another option would be of course to make cornerstone typescript as this gives type declarations for free but I see that's quite a big commitment to make! Also if we decide to go this route it would be wise just starting out with introducing typescript in the public API level, however this is currently tricky because of this open issue in typescript.

That said I think the easiest solution is just to hand write typings and define some procedure to keep them updated. I'm trying to make some time for this as I'm really keen on contributing to cornerstone (and also really keen on working with a type-safe cornerstone API!)

types.d.ts.txt