use satisfies

This commit is contained in:
sfja 2026-03-11 11:51:27 +01:00
parent 0983524ae6
commit 9d72188f48
2 changed files with 5 additions and 5 deletions

View File

@ -35,7 +35,7 @@ type ExprWithKind<Tag extends ExprTag> = Expr & { kind: { tag: Tag } };
The type `ExprKind["Tag"]` is a union of each `tag` value, i.e. in this example `"Int" | "Add"`. Saying `Tag extends ExprTag` means that `Tag` (type) is either `"Int"` or `"Add"`, i.e. for `.is("Int")`, `Tag` will be `"Int"` and for `.is("Add")`, `Tag` will be `"Add"`. The *narrowed* type `ExprWithKind` is defined by saying that we want an `Expr` that specifically has the `kind.tag` value of `Tag`.
Then define a methed that with a *type predicate*:
Then define a method that with a *type predicate*:
```ts
class Expr {
@ -95,7 +95,7 @@ class Expr {
case "Add":
return k.right.eval() + k.left.eval();
}
const _: never = k; // compile time exhaustiveness check
k satisfies never; // compile time exhaustiveness check
}
// ...
}
@ -201,7 +201,7 @@ class Expr {
k.right.visit(v);
return
}
const _: never = k;
k satisfies never;
}
// ...
}

View File

@ -134,7 +134,7 @@ export class MirInterpreter {
);
continue;
}
const _: never = k;
k satisfies never;
}
return Val.Void;
}
@ -158,7 +158,7 @@ class Val {
case "Fn":
return `<${k.fn.ty.pretty()}>`;
}
const _: never = k;
k satisfies never;
}
}