rescript-lang / rescript-lang/rescript

Variables with reserved keywords renamed in output, but not reflected in generated typescript

Open
#6,871 4 comments 1 reaction 1 assignee View on GitHub

@cometkim is already working on this.

Since Jul 26, 2024.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

In our app, we have modules representing entity permissions.
e.g:

// Permissions.res
module Products = {
    let createNew = "createPermissionString"
    let viewExisting = "viewPermissionString"
    let delete = "deletePermissionString"
}

// Permissions.resi
module Products = {
   @genType let createNew: string
   @genType let viewExisting: string
   @genType let delete: string
}

However, because delete is a reserved keyword , the compiler instead renames delete to $$delete without reflecting this in the generated tsx file.

// Permissions.gen.tsx
export const Products_createNew: string = PermissionBS.Products.createNew;
export const Products_viewExisting: string = PermissionBS.Products.viewExisting;
export const Products_delete: string = PermissionBS.Products.delete;

Thus any usage of Products_delete in our typescript code would be undefined because we're not consuming PermissionBS.Products.$$delete.

Ideally, the developer avoids reserved keywords altogether, but if the compiler will allow and rename these, I'd expect the genTyped output to reflect any renaming done by the compiler.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.