Typespec for any struct with required key

I’m looking for a typespec that would match, for instance:

%Foo{specific_key: "abc"}
%Bar{specific_key: "abc"}
%Baz{specific_key: "abc"}

I’m using %{specific_key: String.t()} but that can match maps as well. Is there something like %_{specific_key: String.t()} as there is for pattern matching (%_{...}) for typespec?

1 Like

One option would be specifying the :__struct__ field

%{__struct__: module(), specific_key: String.t()}

Though depending on your use case you may not even want to limit it to structs.

3 Likes