genType for core library

Hey,

I was trying to add @genTypes in my project and I’m encountering this issue in my project.

So it’s trying to look for the *.gen.tsx file for the core libraries types.

Attaching screenshot for the same. This should have by default created the ./JSON.gen or ./Promise.gen files.

How to overcome this issue?

Screenshot 2024-08-20 at 1.59.28 PM

1 Like
{
  "$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
  "name": "----------",
  "jsx": {
    "version": 4,
    "mode": "classic"
  },
  "bsc-flags": ["-bs-super-errors", "-open RescriptCore"],
  "sources": {
    "dir": "src",
    "subdirs": true
  },
  "suffix": ".bs.js",
  "namespace": true,
  "ppx-flags": [],
  "package-specs": {
    "module": "es6",
    "in-source": true
  },
  "bs-dependencies": [
    "@rescript/react",
    "@rescript/core",
    "@glennsl/rescript-fetch"
  ],
  "gentypeconfig": {
    "module": "esmodule",
    "moduleResolution": "node",
    "generatedFileExtension": ".gen.tsx"
  }
}

This is my rescript.json file looks like. Am I missing something in configuration?

I’ve got exactly the same problem. I’m using JSON from core and need to export types to TS land. What do?

Hey, sorry that we didn’t reply earlier, but this should be fixed in the latest alpha of V12. If you use an older version, defining shims files for json and promise should fix it.

I’m on alpha.11 and it doesn’t seem to be fixed. It just generates:

import type {JSON_t as Stdlib_JSON_t} from './Stdlib.gen.ts';

Which I handle by just putting a manual Stdlib.gen.ts file in the same dir. Ugly af, but works:

// Remove this file once genType patch is merged
// https://github.com/rescript-lang/rescript/pull/7378
export type JSON_t = unknown

alpha.11 is older so maybe alpha.12 will handle it properly?

Anyway, re. shims:

Shims don’t work for JSON.t. For shims to work, you have to use shims “Js” and use Js.Json.t instead. Any shims for “JSON” (or any ridiculous combination with Stdlib_ Core_ or double underscores etc) are just ignored in v11.

oops sorry, the fix is indeed in alpha.12 that is not released yet:

1 Like