Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenType does not handle JSON types in Core properly #7157

Closed
jmagaram opened this issue Nov 11, 2024 · 5 comments · Fixed by #7378
Closed

GenType does not handle JSON types in Core properly #7157

jmagaram opened this issue Nov 11, 2024 · 5 comments · Fixed by #7378
Assignees
Labels

Comments

@jmagaram
Copy link
Contributor

Sample project:

https://github.com/jmagaram/functors

Look at file Simple.res with the code:

@genType
let hello = JSON.Encode.string("hello")

The TypeScript is...

import * as SimpleJS from './Simple.res.mjs';
import type {t as Core__JSON_t} from '@rescript/core/src/Core__JSON.gen';
export const hello: Core__JSON_t = SimpleJS.hello as any;

And the error on the second line is...

Cannot find module '@rescript/core/src/Core__JSON.gen' or its corresponding type declarations.

@jmagaram
Copy link
Contributor Author

Might be related to #6563

@cknitt cknitt self-assigned this Mar 6, 2025
@cknitt cknitt added the bug label Mar 6, 2025
@cknitt cknitt moved this to Ready in ReScript development Mar 6, 2025
@cknitt cknitt assigned cristianoc and unassigned cknitt Apr 3, 2025
@tsnobip
Copy link
Member

tsnobip commented Apr 3, 2025

unfortunately, given typescript does not plan to have a JSON type, we'll have to advise users to create a shim for the JSON type for now.

@cristianoc
Copy link
Collaborator

What type should be exported ideally, given that TS does not have a builtin?
Or should it just be any or something like that?

@zth
Copy link
Collaborator

zth commented Apr 3, 2025

unknown is probably the best candidate if we can't find anything that's better. It's slightly better than any, and I also believe it's what JSON.parse returns.

@tsnobip
Copy link
Member

tsnobip commented Apr 4, 2025

What type should be exported ideally, given that TS does not have a builtin? Or should it just be any or something like that?

I guess ideally it would use something like that:

type Json =
  | string
  | number
  | boolean
  | null
  | Json[]
  | { [key: string]: Json };

but you can't define this inline given it's a recursive type.

cristianoc added a commit that referenced this issue Apr 4, 2025
cristianoc added a commit that referenced this issue Apr 4, 2025
cristianoc added a commit that referenced this issue Apr 4, 2025
cristianoc added a commit that referenced this issue Apr 7, 2025
@cristianoc cristianoc reopened this Apr 7, 2025
@github-project-automation github-project-automation bot moved this from Ready to Done in ReScript development Apr 7, 2025
cristianoc added a commit that referenced this issue Apr 7, 2025
* Fix issue with gentype and stdlib json.

Fixes #7157

* Allow both `Stdlib.X` and `Stdlib_X`.

* format

* Update CHANGELOG.md

* Update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants