3 ms·
Isn't Dialyzer's success typing similar to TypeScript in that it's gradual typing? Or am I muddling up my concepts?
by mercer 8y ago
Isn't Dialyzer's success typing similar to TypeScript in that it's gradual typing? Or am I muddling up my concepts?
- yawaramin 8y agoIt's similar and they are both considered gradual typing, yes. Dialyzer is 'better' in some ways though. For example, consider this TypeScript: function f(a) { console.log(a.x); } f({}); With the strictest checks turned on ( try it at https://www.typescriptlang.org/play/#src=function%20f(a)%20%7B%0D%0A%20%20%20%20console.log(a.x)%3B%0D%0A%7D%0D%0A%0D%0Af(%7Bx%3A%201%7D)%3B%0D%0A https://www.typescriptlang.org/play/#src=function%20f(a)%20%... ), TypeScript will give you this message: `Parameter 'a' implicitly has an 'any' type.` Now consider the equivalent Elixir: def test2(), do: f(%{}) def f(a), do: IO.inspect(a.x) Dialyzer will give you this message: `Function test2/0 has no local return ... The call 'YourModule':f(#{}) will never return since it differs in the 1st argument from the success typing arguments: (atom() | #{'x':=_, _=>_})` This is why I said the Dialyzer message takes some getting used to :-) But, it just means that `f` needs to be called with either an atom (because you could pass in a module to the function, and modules are modelled as atoms), or with a map object with the `x` key and possibly some other keys.