typenix: Full typing for Nix based on TypeScript
52 points by knl
52 points by knl
What I find amazing:
How it works: instead of building a new checker for Nix, it maps tree-sitter-nix’s AST directly to TypeScript AST nodes. The standard TS binder, type checker and LSP work almost unchanged – they never know they’re looking at Nix.
What works:
- Hover, go-to-definition, autocomplete on builtins, lib, mkDerivation, much of main pkgs attrset
- Runs on all 42K nixpkgs files in 13s
- And the fun part: Fixed-point patterns (makeExtensible, finalAttrs): typed via transform to a TS class with late this binding
Same here. Even more. The upcoming Go-based TS checker is going to bring types to even more scripting languages for virtually free 🥳
This is one of those things that made me fall for computers.
Using tree-sitter grammar, originally created for syntax highlighting in text editors, used to extract type-information from dynamically typed language, then mapped onto an AST of entirely different statically typed language is just brilliant idea in itself.
And it actually works through full 42k+ files in nixpkgs in reasonable time is friggin amazing! I'm gonna keep an eye on this going forward, this could get big within Nix :)