Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does then extend chain? #246

Closed
ccorcos opened this issue May 11, 2018 · 4 comments
Closed

Why does then extend chain? #246

ccorcos opened this issue May 11, 2018 · 4 comments

Comments

@ccorcos
Copy link

ccorcos commented May 11, 2018

Because then has two type definitions, there are a bunch of type errors that I've missed.

It would be nice if then was distinctly different from chain.

		/**
		 * returns a new parser which tries parser, and on success calls the given function
		 * with the result of the parse, which is expected to return another parser, which
		 * will be tried next
		 */
		chain<U>(next: (result: T) => Parser<U>): Parser<U>;
		/**
		 * returns a new parser which tries parser, and on success calls the given function
		 * with the result of the parse, which is expected to return another parser.
		 */
		then<U>(call: (result: T) => Parser<U>): Parser<U>;
		/**
		 * expects anotherParser to follow parser, and yields the result of anotherParser.
		 * NB: the result of parser here is ignored.
		 */
		// tslint:disable-next-line:unified-signatures
		then<U>(anotherParser: Parser<U>): Parser<U>;
@wavebeem
Copy link
Collaborator

Hi @ccorcos! I do not maintain the @types/parsimmon package and have never given any input on it. This would be a bug to report to the DefinitelyTyped project.

However, I will say this appears to be a bug in the type definitions, as the then<U>(call: (result: T) => Parser<U>): Parser<U> signature for then has not been supported since pre-1.x Parsimmon.

I am strongly considering adding TypeScript support directly to Parsimmon in the future, but there are various difficulties keeping me from adding it to Parsimmon 1.x and you will probably need to wait until 2.x for official support.

@ccorcos
Copy link
Author

ccorcos commented May 11, 2018

Sound good, thanks @wavebeem. I highly recommend TypeScript btw 👍

@wavebeem
Copy link
Collaborator

@ccorcos I love TypeScript too :) It's just difficult to get some of Parsimmon's idioms working well in TypeScript, and ES Classes have some strange features that don't mesh well with Parsimmon either. But I definitely wanna get in on it for this library eventually.

@wavebeem
Copy link
Collaborator

If you have any additional thoughts about TypeScript for Parsimmon, feel free to discuss here #230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants