rrdelaney / ReasonablyTyped

:diamond_shape_with_a_dot_inside: Converts Flow and TypeScript definitions to Reason interfaces
https://rrdelaney.github.io/ReasonablyTyped/
MIT License
518 stars 24 forks source link

Spread Arg Support #9

Closed bbqbaron closed 7 years ago

bbqbaron commented 7 years ago

From #7, this adds support for parsing spread/variadic args in type annotations. Any Flow variadic becomes a BS named array. If it's optional, my tests are also expecting an extra unit arg, which as far as I can tell was already built into the code and therefore must be correct :).

Any Ocaml idioms I missed? Extra/dangerous test cases you can think of?

rrdelaney commented 7 years ago

Thanks so much for PR! I really appreciate you taking a shot at this! All the code looks good! The only problem is I don't think the bindings produced compile to the correct code 😕

Using this Flow code:

declare module 'spread-args' {
  declare export function foo(...bars: number[]): void
}

I get this binding:

external foo : bars::array float => unit = "" [@@bs.module "spread-args"];

But when I call it BuckleScript produces the following output:

var SpreadArgs = require("spread-args");

SpreadArgs.foo(/* float array */[
      1,
      2
    ]);

The call should look like:

var SpreadArgs = require("spread-args");

SpreadArgs.foo(
      1,
      2
    );

I think the right place to look in the manual is @@bs.splice

Thanks again for this awesome work 😄

bbqbaron commented 7 years ago

Oh, duh. Inexperienced with BS usage, sorry. Will check out splice, update tests and code shortly! On Sat, Jul 8, 2017 at 19:16 Ryan Delaney notifications@github.com wrote:

Thanks so much for PR! I really appreciate you taking a shot at this! All the code looks good! The only problem is I don't think the bindings produced compile to the correct code 😕

Using this Flow code:

declare module 'spread-args' { declare export function foo(...bars: number[]): void }

I get this binding:

external foo : bars::array float => unit = "" [@@bs.module "spread-args"];

But when I call it BuckleScript produces the following output:

var SpreadArgs = require("spread-args"); SpreadArgs.foo(/ float array /[ 1, 2 ]);

The call is should look like:

var SpreadArgs = require("spread-args"); SpreadArgs.foo( 1, 2 );

I think the right place to look in the manual is @@bs.splice https://bucklescript.github.io/bucklescript/Manual.html#_splice_calling_convention_bs_splice

Thanks again for this awesome work though 😄

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rrdelaney/ReasonablyTyped/pull/9#issuecomment-313886590, or mute the thread https://github.com/notifications/unsubscribe-auth/AGxb_ejt2hsrJb6hGCUawWTfxNn_RM9Oks5sMA3pgaJpZM4OQ6ad .

rrdelaney commented 7 years ago

Yea, I didn't know anything about BS either before starting this! I'm still learning stuff 🙂

The Reason playground is a really good place to test the output too

bbqbaron commented 7 years ago

Okay, so, back with many improvements.

bbqbaron commented 7 years ago

Ah; conflicts. Resolving soon.

rrdelaney commented 7 years ago

The conflicts should be from adding type params to functions - let me know if you need help 😄

bbqbaron commented 7 years ago

Sweet: