Is Dialyzer useful for Phoenix + Ecto.Structs?

Hello.

I am a programmer who is learning Elixir from other typed languages.

Even though there’s some verbosity, In Typed Languages, I can say there is no misspelled property name in my code, once my code is compiled.

I thought the Struct can give me something similar, But it seems not.

I could add unregistered key to Struct when i use
%A{a: 1} |> Map.put(:b, 2)

And also
%{a |b: 2} syntax only raises errors on Run-time.

Does anybody know, How I can get more strict key name safety or at least better linting?

Thank you in advance.

Use struct/2 instead of Map.put.

2 Likes

Thank you. I did not know about that, but I prefer to catch this kind of mistakes in compile time if possible.

1 Like

%MyStruct{a | b: 2} won’t compile.

2 Likes

It compiles fine, it will just error at runtime if a is not a MyStruct. This is just some of the limitations of languages deficient in typing.