ReScript HomeReScript Home
DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact

Syntax Lookup

Enter some language construct you want to know more about.
A variant type models a value as one of several named constructors.

A variant type lets you represent different cases in one type.

Example

ReScriptJS Output
type myResult<'a> =
  | MyVariant('a)
  | Error(string)

let response = MyVariant(42)

let message = switch response {
| MyVariant(value) => "Success: " ++ Int.toString(value)
| Error(err) => "Error: " ++ err
}

References

  • Variant

  • Pattern Matching

© 2026 The ReScript Project

About
  • Community
  • ReScript Association
Find us on