Dialyzer partial map

Is there a way to specify a map in which you certain keys are required, but you want to extra keys that you won’t know in the future? We’re wrapping an external api that allows you to submit custom data alongside the required fields and want do provide typespecs.

For example, the api could require the minimum map %{a: a, b: b}, but the user should be able to pass any other keys, like %{a: a, b: b, c: c}

I guess the idiomatic way would be to merge a required map with an options map, but it would be nice to only have one parameter instead.

@type required_params :: %{
  a: integer,
  b: integer

@type optional_params :: map()

@spec foo(
def foo(req, options \\ %{}) do
  Map.merge(req, options

optional(any) => any, or whatever types you need for them.

1 Like

Thanks so much!