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

Optional Parameters with TypeScript and Flow #1569

Closed
johnnycoyleST opened this issue May 31, 2018 · 7 comments
Closed

Optional Parameters with TypeScript and Flow #1569

johnnycoyleST opened this issue May 31, 2018 · 7 comments

Comments

@johnnycoyleST
Copy link

I have a question about using mobx 4's async flow in conjunction with TypeScript (strict mode). What is the best way to handle optional parameters being passed to the generator function. Here's an example of what I'm talking about:

    init = flow(function * (foo: string, bar?: number) {
	//do some asychronous action
    });

The above would lead to the compilation error:

"TS2554: Expected 1 arguments, but got 2"

I was able to get around this by wrapping flow in a HoF that handles the optional params. Is there another solution to this, or has that functionality not yet been integrated for flow?

@kuitos
Copy link
Member

kuitos commented Jun 5, 2018

Can't reproduce the compilation error with mobx 4.2.0, ts 2.8.1

const init = flow(function *(name: string, age?: number) {
	yield console.log(name);
	yield console.log(age);
});

can u provide a jsfiddle link or any other similar demos?

@kanoshin
Copy link

kanoshin commented Jun 7, 2018

@kuitos just try to call function that you created with 2 parameters and you would get an error:
screen shot 2018-06-07 at 3 14 53 pm

@ethanyou725
Copy link

the same to me.

@dassennato
Copy link

Same here!

@MatthieuCoelho
Copy link

Same here

@mweststrate
Copy link
Member

Potentially fixed by #1816

@stale
Copy link

stale bot commented Jun 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 🚶 stale label Jun 19, 2019
@stale stale bot closed this as completed Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants