I noticed something weird about my .gen.tsx
files. Why is it wrapping all of my (arity >= 2) functions with this Curry
helper?
Client.gen.tsx
// @ts-ignore: Implicit any on import
import * as Curry__Es6Import from 'rescript/lib/es6/curry.js';
const Curry: any = Curry__Es6Import;
// @ts-ignore: Implicit any on import
import * as ClientBS__Es6Import from './Client.bs';
const ClientBS: any = ClientBS__Es6Import;
import type {Headers_t as Fetch_Headers_t} from '../src/shims/Fetch.shim';
import type {Map_String_t as Belt_Map_String_t} from '../src/shims/Belt.shim';
export type t = { readonly baseUrl: string; readonly headers: Belt_Map_String_t<string> };
export const make: () => t = ClientBS.make; // âś… good
export const headers: (client:t) => Fetch_Headers_t = ClientBS.headers; // âś… good
export const setBaseUrl: (client:t, baseUrl:string) => t = function (Arg1: any, Arg2: any) {
const result = Curry._2(ClientBS.setBaseUrl, Arg1, Arg2); // âť“why
return result
};
export const setHeader: (client:t, param:[string, string]) => t = function (Arg1: any, Arg2: any) {
const result = Curry._2(ClientBS.setHeader, Arg1, Arg2); // âť“why
return result
};
I think it should be as simple as linking the uncurried versions from the .bs.js
file -
// …
export type t = { readonly baseUrl: string; readonly headers: Belt_Map_String_t<string> };
export const make: () => t = ClientBS.make;
export const headers: (client:t) => Fetch_Headers_t = ClientBS.headers;
export const setBaseUrl: (client:t, baseUrl:string) => t = ClientBS.setBaseUrl // âś…
export const setHeader: (client:t, param:[string, string]) => t = ClientBS.setHeader // âś…
Client.bs.js already includes uncurried versions -
function make(param) {
return {
baseUrl: "",
headers: Belt_MapString.fromArray([[
"Content-type",
"application/json"
]])
};
}
function headers(client) {
return new Headers(Belt_MapString.toArray(client.headers));
}
function setBaseUrl(client, baseUrl) {
return {
baseUrl: baseUrl,
headers: client.headers
};
}
function setHeader(client, param) {
return {
baseUrl: client.baseUrl,
headers: Belt_MapString.set(client.headers, param[0], param[1])
};
}
Here’s the original Client.res
file -
@gentype
type t = {
baseUrl: string,
headers: Belt.Map.String.t<string>,
}
@gentype
let make = (): t => {
{
baseUrl: "",
headers: Belt.Map.String.fromArray([("Content-type", "application/json")])
}
}
@gentype
let headers = (client: t) => {
client.headers->Belt.Map.String.toArray->Fetch.Headers.fromArray
}
@gentype
let setBaseUrl = (client: t, baseUrl: string): t => {
{
...client,
baseUrl: baseUrl
}
}
@gentype
let setHeader = (client: t, (header: string, value: string)): t => {
{
...client,
headers: client.headers->Belt.Map.String.set(header, value)
}
}