Building types and checks for external functions : Future Plans
baldwindavid opened this issue · comments
I saw in the recent release announcement that there was some great work done on reading regular @type/@spec
definitions... https://elixirforum.com/t/typecheck-fast-and-flexible-runtime-type-checking-for-your-elixir-projects/32886/95#building-types-and-checks-for-external-functions-3 by @orsinium
I understand that at this point, it is more for manual usage, but that it might be further integrated for simplifying the override of remote types. Is the idea that at some point you might be able to do something like...
defmodule MyMod do
use TypeCheck, fetch_external_types: true # maybe this is the default
@spec! user_older_than?(User.t(), integer()) :: boolean()
def user_older_than?(user, age) do
user.age >= age
end
end
In this example, User.t()
may or may not be annotated with a @type! t
(with a bang) specification. If there is a TypeCheck specification it will use it. Otherwise, it would try to find an external @type t
. Is that how you are envisioning it?
Yep, there is a lot more that can be done. I also thought about having something like what typeguard has for checking all types in specific packages during tests. Something like doctest
but for types (typetest
?) I'm not sure if I personally will have time to bring any of it, though. I hoped to become an Elixir developer and focus my contributions on Elixir ecosystem, but I haven't found any Elixir job :(
Is that how you are envisioning it?
Yes, exactly!
It is not always what you want (in other words: I do not see manual type overrides to fully go away) because sometimes you do need/want to make the type that is used for runtime type-checking (and/or spectesting) more precise than what is available in the non-TypeCheck @type/@spec
. But in many cases it will be a very nice and simple way to integrate TypeCheck with existing code.
Some other ideas are to for instance use it to add checks to implementations of a behaviour (c.f. #106 ), where we could support both TypeCheck and non-TypeCheck behaviours.
And I'm pretty sure that there are other things that could be done as well 😄.
Closing this discussion issue for now 😊 .