TODAY I LEARNED
by lubosmato
by lubosmato
In the default branch, TypeScript narrows proto to whatever union members weren't handled. If all cases are covered, proto becomes never and the check passes silently. If you miss a case (like "raw" here), proto still has a remaining type, so satisfies never produces a compile-time error telling you exactly which variant you forgot to handle.
This statement lets you insert rows into a table by pulling data from another table (or the same table) using a SELECT query, rather than specifying values manually.
-- Assume both tables have the same structure
INSERT INTO orders_archive (order_id, customer_id, total, order_date)
SELECT order_id, customer_id, total, order_date
FROM orders
WHERE status = 'completed' AND order_date < '2025-01-01';type Proto = "tcp" | "http1" | "raw"
const proto = "tcp" as Proto
switch (proto) {
case "tcp":
case "http1":
break;
default:
proto satisfies never; // <-- Type '"raw"' does not satisfy the expected type 'never'.
}