rescript-association / genType

Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType.

Home Page:https://rescript-lang.org/docs/gentype/latest/introduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Named arguments when exporting only a subset via an interface file?

sgrove opened this issue · comments

I think it's not quite possible to get named arguments in the gentype output for resi files currently.

e.g.:

// .res
let parse = (uriString: string): uri => {


// .resi
@genType
let parse: string => uri

// .gen.tsx
export const parse: (_1:string) => uri = QueryBS.parse;

vs with no .resi file:

// .tsx
export const parse: (uriString:string) => uri = QueryBS.parse;

I understand this may or may not be possible with what's available to gentype, but it'd be nice to pass through named arguments (even via a gentype.as annotation. e.g. @genType let toString: [@genType.as("myUri") uri] => string)

Wondering whether there's ever a case when one would want to "hide" the variable names used in the implementation. Can't think of one.
Looks like just taking the info from the implementation, would work fine.
genType has not used all the tricks in the book, but the editor support has, and it accesses all sort of info, from interface, implementation, original verbatim code, result of the parser etc. So one can assume that all that info is within reach in terms of what's possible.

How involved do you think this would be @cristianoc? This would be a great addition when creating libraries to be consumed on the TS side.

This should move to the compiler repo, where gentype now lives.
I think exporting selected arguments is only possible in uncurried mode.
Also, the function should take an object instead of several arguments, which is not how functions are compiled.

And zero cost means the function can't be wrapped.

In short, this is more a question about core language semantics than gentype, which will just follow what the compiler does.

This repository is being archived. If you feel like the issue still relevant, please re-create it in the compiler repo. Thanks!