TypeSpec: Combining maps

Hey there folks,

A colleague asked me if there is a way to use an already defined type that is a map and add additional fields to it.

The following may suffice as an example:

Given the Template

@type person :: %{
  last_name: String.t(),
  first_name: String.t(),
  birth_date: String.t()
}

he wants to use this type later on like this

@type buyer :: %{ person: person | address: String.t()}

The result would be an stricter contract.

I see that there are multiple problems with that approach as a change in the person contract would lead to unforeseen changes in other contract. So I am asking more for curiosity: Does TypeSpec support such structures?

1 Like

It doesn’t.

2 Likes