glTF-Validator icon indicating copy to clipboard operation
glTF-Validator copied to clipboard

Typescript declaration file for API

Open shrinktofit opened this issue 6 years ago • 9 comments

Hey I just wrote the declaration file according to document and what I tried. Hope this helps and if so, please publish it to npm . Code

shrinktofit avatar Mar 20 '19 10:03 shrinktofit

@shrinktofit that's great! Do you know where are the hints?

Shouldn't it be:

export const enum Severity {
        Error = 0,

        Warning = 1,

        Information = 2,

        Hint = 3,
    }

ranbuch avatar Oct 24 '19 11:10 ranbuch

Ok, I have updated it.

shrinktofit avatar Oct 28 '19 08:10 shrinktofit

Nice! We wrote something similar for Babylon.js. Do you mean to use https://github.com/shrinktofit/gltf-validator-typing/blob/master/index.d.ts#L53-L58 in https://github.com/shrinktofit/gltf-validator-typing/blob/master/index.d.ts#L81-L86?

bghgary avatar Oct 28 '19 16:10 bghgary

Nice! We wrote something similar for Babylon.js. Do you mean to use https://github.com/shrinktofit/gltf-validator-typing/blob/master/index.d.ts#L53-L58 in https://github.com/shrinktofit/gltf-validator-typing/blob/master/index.d.ts#L81-L86?

Yes it should be typo. I have removed it. By the way, I change the Severity from const-enum to type to avoid isolatedModule issue.

shrinktofit avatar Oct 30 '19 09:10 shrinktofit

Should this go into the main repo for distribution via npm?

emackey avatar Nov 12 '19 19:11 emackey

How is this coming along? Would be good to have these available (at least at @types/gltf-validator)

garysb avatar Feb 27 '20 15:02 garysb

I'm interested in type definitions as well. If there's consensus on where the type declarations should be kept, I can open a PR.

  • (a) Publish externally to DefinitelyTyped, as @types/gltf-validator
  • (b) Add to this project, publish to NPM as part of gltf-validator package

@lexaknyazev can you refresh my memory on the index.ts file? Is it automatically generated or manually maintained? And do we use it for anything other than generating the API docs in the NPM readme? If it's hand-written and just used to generate docs, I would recommend we replace it with a TS definitions file so there's only one thing to maintain. We can still generate docs from that, and then TS users would have type declarations too.

If we'd have to maintain two files by hand here, then instead I'd suggest we push this to DefinitelyTyped, i.e. external maintenance (https://github.com/DefinitelyTyped/DefinitelyTyped).

donmccurdy avatar Apr 02 '21 17:04 donmccurdy

I recently ran into this issue and I have time at the moment to fix this unless you have a PR sitting off to the side, @donmccurdy.

Some thoughts:

  • I feel like option b is the better of the two options.
  • It looks like grinder only copies the index.js and module.mjs files, so these appear to be manually created. We can add a index.d.ts that is copied in the same fashion.
  • index.js is the entry point for the NPM package, so I don't think we can replace it.

Please let me know what you all think. I may just open a PR in a day or two if there's no feedback.

weegeekps avatar Jul 21 '21 19:07 weegeekps

I think (b) would be good, the API surface is narrow enough that this should not be much trouble to maintain I hope. For larger libraries with more API surface, and where the authors are not using TypeScript themselves, I tend to advise (a).

donmccurdy avatar Aug 12 '21 02:08 donmccurdy