This form is not allowed as the type of the inlined record could escape

I haven’t come across this error yet: This form is not allowed as the type of the inlined record could escape..

Here’s where I use the code:

@jsx.component
let make = (~data: data) => {
  switch data->Plex.getFirstMovieFromMediaContainer {
  | Some(Movie(movie)) => {
      Console.log(movie)  // <-- error is here
      let {title} = movie
      <Movie title />
    }
  | _ => <div> {Preact.string("Movie not found.")} </div>
  }
}

And the type definition:

type media =
  | @tag("type") @as("season") Season({parentTitle: string})
  | @tag("type") @as("movie") Movie({title: string, thumb: string, ratingKey: int})

You defined an inline record inside of a variant, so you can’t create a variable of this inline type, you have to pattern match on its fields to to access them, like this:

@jsx.component
let make = (~data: data) => {
  switch data->Plex.getFirstMovieFromMediaContainer {
  | Some(Movie({title, thumb, ratingKey})) => {
      Console.log3(title, thumb, ratingKey)  // <-- works now
      <Movie title />
    }
  | _ => <div> {Preact.string("Movie not found.")} </div>
  }
}

Gotcha, that makes sense. This is probably an error message that could be made more clear :slight_smile:

1 Like

PR are always welcome, making error messages nice and clear is not an easy task!