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

Inline Record in Variant #72

Open
jeong-sik opened this issue Feb 29, 2024 · 1 comment
Open

Inline Record in Variant #72

jeong-sik opened this issue Feb 29, 2024 · 1 comment

Comments

@jeong-sik
Copy link

Hi! Thanks as always for your great libraries.

I was trying out discriminated union with the new syntax @tag and faced the following problem.

module Message = {
  @tag("type") @spice
  type t =
    | TEXT({id: string, userKey: string, createdAt: string, text: string})
    | IMAGE({id: string, userKey: string, createdAt: string, imageFileId: string})
    | RAW_FILE({id: string, userKey: string, createdAt: string, fileId: string})
}

@spice
type someResponse = {
  lastMessage: Message.t
}

Log

[rewatch] This syntax is not yet implemented by spice

But, define record type, It can compiled.

Like this

module Message = {
  @spice
  type text = {id: string, userKey: string, createdAt: string, text: string}
  @spice
  type image = {id: string, userKey: string, createdAt: string, imageFileId: string}
  @spice
  type rawFile = {id: string, userKey: string, createdAt: string, fileId: string}
  @tag("type") @spice
  type t =
    | TEXT(text)
    | IMAGE(image)
    | RAW_FILE(rawFile)
}

@spice
type someResponse = {
  lastMessage: Message.t
}
[7/7] ️✅  Finished Compilation in 0.83s

It would be nice if spice also implemented inline records in variants. 😄

Actually
rescript-lang/rescript#6547

If this feature is applied, no additional changes to spice will be required lol.

@jeong-sik
Copy link
Author

jeong-sik commented Feb 29, 2024

#59
Sorry, it was already in the RFC! 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant