Difficulty with shims and Undefined.t<...> and Null.t<...>

I started using the Core library. I also use a lot of GenType. In my code I’m using expressions like Null.t<string> and Undefined.t<string>. The GenType .tsx file is showing errors on these lines saying the .gen files are missing. I can’t get it to work. What specific shims files do I need? Can I put everything in one shim file or is there some special naming convention?

I don’t understand the bsconfig.json settings. What is the first parameter and what is the second? I’ve tried various flavors of Core.Undefined, Core__Undefined, etc. but can’t figure out the magic configuration needed.

import type {t as Null_t} from './Null.gen';
import type {t as Undefined_t} from './Undefined.gen';

Ugh! Each time I see these kinds of errors I worry whether I’ll be able to resolve it. Maybe the documentation for shims need improvement? I created two files inside my shims folder - Null.shim.ts and Undefined.shim.ts. Here’s what is inside the Undefined.shim.ts

export type t<A> = A | undefined;

Here is my bsconfig.json

{
  "name": "hotkeys",
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    }
  ],
  "package-specs": [
    {
      "module": "es6",
      "in-source": true
    }
  ],
  "suffix": ".bs.js",
  "bs-dependencies": ["rescript-struct", "@rescript/core"],
  "bsc-flags": ["-open RescriptCore"],
  "gentypeconfig": {
    "language": "typescript",
    "shims": { "Js": "Js", "Undefined": "Undefined", "Null": "Null" },
    "generatedFileExtension": ".gen.tsx",
    "module": "es6",
    "debug": {
      "all": false,
      "basic": false
    }
  }
}

Can you add an issue to the compiler repo – these are things that one can look into supporting out of the box.

See the PR here: Add `Core` standard library support for `genType` by cristianoc · Pull Request #6019 · rescript-lang/rescript-compiler · GitHub

1 Like