Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ash type-inference demo

This project demonstrates experimental compile-time type checking for Ash action inputs. It intentionally contains invalid callback code, so its compiler warnings are the expected output.

Run the demo

git clone https://github.com/Alt-iOS/ash_type_inference_demo.git
cd ash_type_inference_demo
mix deps.get
mix compile --warnings-as-errors

The final command should fail with type diagnostics. To print the same warnings without treating them as errors:

mix compile --force

The project uses the feature/typed-action-input-inference branches of the Alt-iOS Ash and Spark forks.

Demonstrated cases

  • Exact action-argument and accepted-attribute keys
  • Primitive value types and nilability
  • Constrained maps
  • Embedded resources and arrays of embedded resources
  • Inputs passed through manage_relationship
  • Inline and dispatched changes
  • change/3, atomic/3, and batch_change/3
  • Validations and preparations
  • Literal callback options
  • Friendly diagnostics for invalid fields on %Ash.Changeset{}

Each module is in a separate file so dispatched, cross-module inference is visible.

Inspect the generated witnesses

The compiler builds type-witness modules in memory. Print their generated Elixir source with:

mix run --no-compile -e '
Ash.Resource.TypeInference.witness_entries([AshTypeInferenceDemo.Resource])
|> Enum.each(fn entry ->
  IO.puts("\n# #{inspect(entry.key)}\n")
  IO.puts(Macro.to_string(entry.definition))
end)
'

About

Simple demo of an experiment

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages