kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.57k stars 231 forks source link

Official type definitions? #577

Open corwin-of-amber opened 3 years ago

corwin-of-amber commented 3 years ago

Cheers!

It seems that the type definitions at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/nearley are a bit outdated. For example, the Parser constructor is provided as:

    constructor(grammar: Grammar, options?: ParserOptions);

Whereas the JS definition is https://github.com/kach/nearley/blob/be339244f1f2fde30d8dc163c66da2d3b1537095/lib/nearley.js#L242.

Perhaps it's time to bring those definitions over and have them as part of the nearley package, removing the need for @types/nearley and also making the types consistent with the implementation?

corwin-of-amber commented 3 years ago

(I see now that there are actually two possible constructors and that the JS code resolves the overloading.)

kach commented 3 years ago

Hey Shachar, good to hear from you. Again, I'm not a typescript expert, but if you think this is a reasonable thing to do and want to submit a PR, I'm happy to look it over.

corwin-of-amber commented 3 years ago

Yes I was actually going to suggest myself for the job but didn't want to step on anyone's toes in case they're already working on it :) I can definitely adapt the definitions from DefinitelyTyped; I assume some tests for these are also in order, will you be ok with some tests being written in TypeScript?

kach commented 3 years ago

Go ahead! Though to be clear, I only want TypeScript-related features tested in TypeScript. Also, please don't make any backwards-incompatible changes.