The type checker doesn't read my posts
astro check reads .astro and .ts files and never opens an .mdx one, so every prop I pass inside a post is unchecked. One of 3 places here where the types stop.
Somebody asked me whether the drawings on this site were typesafe. They’re a list of points in a TypeScript file, so the answer should have been yes, and what I said was “mostly”. That’s the worst available answer to that question. It means I hadn’t looked.
So I looked. Three things turned out to sit outside the type checker, and they aren’t worth the same.
A class name is a string, and I was holding both ends of it
A part of a drawing doesn’t name a colour, it names a role: line, mass, skin,
paper. Those are a union in ink.ts. What paints them is a set of
.illo-fill-* rules in the stylesheet. Nothing joins a TypeScript union to a
CSS file except the string in the middle, and I was building that string with a
template.
Get it wrong and the path carries a class no rule matches. SVG’s initial fill is black, so the shape comes out black on the light theme, the red one and the dark one, and every test I had would let it through: it’s the right size, it’s inside the canvas, and it has plenty of contrast against the page. Looking at the drawing is what catches it.
That one was worth closing from both ends. Every class in the kit now comes out
of one function, fillClass(fill: Fill), which puts my half back under the
compiler. The stylesheet’s half is a test: it loads the 2 index pages, takes the
illo-fill-* classes off the page and the .illo-fill-* selectors out of the
stylesheets the page loaded, and fails when a class has no rule behind it. I
renamed a rule to check it, and it failed by name.
astro check never opens a post
This is the one I’d have bet against. Posts here are MDX, MDX imports
components, and those components have real prop types. (I didn’t believe it
either, so I went and read check.js in the language server. It globs
**/*.astro.)
So nothing I write in a post is checked. A scene name with a letter out of place, a screenshot with no alt text, a size that isn’t one of the 3 the component knows, a prop whose name is a near miss for a real one and does nothing at all. There’s no flag to turn on. The 3 components a post passes props to check themselves as they render instead, and I wrote each mistake into a real entry to see what came back:
CaseFigure /_astro/unbloat-checklist-docker.png: size is one of wide, phone, terminal, not "phne"
CaseFigure /_astro/sninat-search.png: needs alt describing the image itself
PostScene Museum: no prop called align
Arrow: dir is one of right, left, down, not "rihgt"
They fire when the page renders, so a mistake costs a build and not a red line under the word while I’m typing. That’s the trade, and there isn’t a better one going.
An array index, and 98 errors of housekeeping
astro/tsconfigs/strict turns on strict and stops. noUncheckedIndexedAccess
lives in strictest, so points[0] had the type Point whether or not there
was a point there, in a file that does little but index: the 4 neighbours a
Catmull-Rom segment needs, the ends of a stroke, the outline perfect-freehand
hands back as number[][].
Turning it on produced 98 errors, two thirds of them in that one file. The ones
in that file went to at(points, i, closed), which wraps the index round a
closed ring or clamps it to an open line, then throws if the list was empty. The
file says once that a drawing needs at least one point, and nothing else in it
asserts. The rest was 4 test files learning to say out loud that an rgb string
gives back 3 numbers.
function at(points: readonly Point[], i: number, closed: boolean): Point {
const count = points.length;
const point = closed
? points[((i % count) + count) % count]
: points[Math.max(0, Math.min(count - 1, i))];
if (!point) throw new Error("ink: a drawing needs at least one point");
return point;
}
This one has never caught anything. No drawing has been built from an empty list and probably none ever will be. It stays on because the day it does fire, the symptom is a NaN in a path and a shape that silently isn’t there, and I’d rather spend the afternoon now than then.