Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

exportInterfaces:true doesn't work with labeled arguments #561

Closed
tsnobip opened this issue May 31, 2021 · 6 comments
Closed

exportInterfaces:true doesn't work with labeled arguments #561

tsnobip opened this issue May 31, 2021 · 6 comments

Comments

@tsnobip
Copy link

tsnobip commented May 31, 2021

if you have "exportInterfaces": true in your bsconfig.json and have this inside Foo.res:

@genType
type bar = {baz: int}

@genType
let process = (~bar) => bar.baz

This is generated in Foo.gen.ts:

/* TypeScript file generated from Foo.res by genType. */
/* eslint-disable import/first */


// @ts-ignore: Implicit any on import
const FooBS = require('./Foo.bs');

export interface Ibar { readonly baz: number };

export const process: (_1:{ readonly bar: bar }) => number = function (Arg1: any) {
  const result = FooBS.process(Arg1.bar);
  return result
};

As you can see, the type bar doesn't exist and should be Ibar.

@cristianoc
Copy link
Collaborator

Indeed, thanks for reporting.
The setting exportInterfaces is kind of experimental.
Would you explain your use case? Would you use it frequently or is this only an experiment?

@tsnobip
Copy link
Author

tsnobip commented Jun 1, 2021

Yeah I know it's kind of experimental and we started using it recently but I think it's very convenient for one use-case.

Let's say you have to deal with a very complex type from typescript but only use a subset of it from rescript, what we do is that we define this subset in rescript as an interface with genType then import it from typescript and extend this interface to add the fields we only use in typescript.

I could otherwise define the type entirely in rescript and import the types from typescript as opaque types for the fields I don't use in rescript, but it's a bit cumbersome and easily leads to circular dependencies.

@cristianoc
Copy link
Collaborator

Maybe it makes sense to activate it on specific values/files, and move it off being an experimental option.
First though I'd need to check that this does not require information to travel across files.

cristianoc added a commit that referenced this issue Jun 2, 2021
@cristianoc
Copy link
Collaborator

@tsnobip here's a fix:
#563

Let me know if it solves your general problem.

@tsnobip
Copy link
Author

tsnobip commented Jun 2, 2021

Thanks a lot @cristianoc.
Do you have any example of using a version of genType from a PR?
When using "gentype": "rescript-association/genType#pull/563/head" I get this error:

Fatal error: exception Failure("gentype/gentype.exe not found when resolving gentype.exe")

@tsnobip
Copy link
Author

tsnobip commented Jun 2, 2021

OK I have cloned it and built it and it indeed solves the issue, thanks @cristianoc :)

cristianoc added a commit that referenced this issue Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants