diff --git a/book-src/tour/custom-types.md b/book-src/tour/custom-types.md index 5a03a13a..20a96798 100644 --- a/book-src/tour/custom-types.md +++ b/book-src/tour/custom-types.md @@ -250,3 +250,25 @@ LoggedIn("Kim") guest, {logged_in, <<"Kim">>}. ``` + +## JavaScript interop + +When compiling to JavaScript, each constructor becomes a class of the same name. +Each of the generated JavaScript classes has a constructor with the same +arguments as the original type constructor. + +```gleam +// Gleam +Guest +LoggedIn("Kim") +Cat(name: "Jinx", cuteness: 2002) +``` + +```javascript +// JavaScript +import { Guest, LoggedIn, Cat } from "my_module.mjs"; + +new Guest(); +new LoggedIn("Kim"); +new Cat("Jinx", 2002); +```