Error: label defined in both types in the context of a recursive type

Here’s a simplified example of code that’s similar to what I’m working on that’s throwing the following error: the label game_key is defined in both types transitionData and addData.

type rec t = 
  | Transition(transitionData)
  | Add(addData)
and transitionData = { game_key: string, /* and other fields */ }
and addData = {game_key: string, event: t, /* and other fields */ }

My first thought was to just wrap the problematic types in their own modules, but how would I do that with this recursive type?

This is compiling successfully for me:

type transitionData = {game_key: string}

type rec addData = {game_key: string, event: t}
and t =
  | Transition(transitionData)
  | Add(addData)

Sorry,
I’ve updated the example so that both data types include the event.

type rec t =
  | Transition(transitionData)
  | Add(addData)
and transitionData = {game_key: string, event: t}
and addData = {game_key: string, event: t}

In the playground it generates a warning so my bsconfig is likely treating it as an error.

Maybe I can just ignore the warning?

Yes, I think so.

https://rescript-lang.org/try?version=v10.1.2&code=ALDuEMCcDsEtoOYAoBEBaAzABhQSgFAAuAngA4CmABJOQMaWGUC8+llAPpQCqTjQDOsQrAD20JIV4Cho6ABFwhcATacAggBMNScFoVKCfDQymDhY-eGaUA3gnABbcgH0A1uWIAuSv0nwEADSU5ABu5NCE3oQAvvhGlLoaltZ2ji7uXj5+iEGh4ZEMsSAQMP6oANTYePhAA

Edit: Some context

1 Like