Things I Learned This Week #2


Another week, a few things worth writing down.

TypeScript’s satisfies Operator

I kept reaching for type assertions where I should have been using satisfies. The difference matters:

// Type assertion — you're telling TS to trust you
const config = {
  port: 3000,
  host: "localhost",
} as ServerConfig;

// satisfies — TS validates AND preserves the literal type
const config = {
  port: 3000,
  host: "localhost",
} satisfies ServerConfig;

With as, TypeScript won’t catch typos in property names. With satisfies, it validates the shape against ServerConfig but keeps the narrower inferred type — so config.port is 3000, not number.

Useful for config objects and lookup tables where you want both validation and precise types.

CSS Container Queries in Practice

I finally used container queries in a real project this week rather than just reading about them. The mental shift from viewport-based to container-based thinking is worthwhile.

.card-grid {
  container-type: inline-size;
  container-name: card;
}

@container card (min-width: 400px) {
  .card {
    display: grid;
    grid-template-columns: auto 1fr;
  }
}

The thing that surprised me: components genuinely become more reusable. A card that adjusts to its container works correctly whether it’s in a sidebar, a full-width section, or a modal — no extra modifier classes.

Browser support is now good enough that I’m using this without a polyfill. The one rough edge is that you still can’t query a container’s height — block-size queries aren’t widely supported yet.

Structuring Go CLI Flags

Been working on a small Go CLI tool and found a clean pattern for organizing flags that avoids the global variable mess:

type Flags struct {
    Verbose bool
    Output  string
    DryRun  bool
}

func parseFlags() Flags {
    var f Flags
    flag.BoolVar(&f.Verbose, "verbose", false, "enable verbose output")
    flag.StringVar(&f.Output, "output", "stdout", "output destination")
    flag.BoolVar(&f.DryRun, "dry-run", false, "print actions without executing")
    flag.Parse()
    return f
}

func main() {
    flags := parseFlags()
    run(flags)
}

Passing flags as a value through the call stack means every function’s dependencies are explicit. No reaching for package-level variables, no hidden state. Testing is easier because you can call run(Flags{DryRun: true}) directly.

Not a novel pattern, but it took me longer than it should have to stop using flag.Bool and global vars.

A SQLite Extension Worth Knowing About

sqlite-vec is a SQLite extension for vector search — nearest-neighbour queries on embeddings, stored in a regular SQLite file. Useful if you want simple semantic search without standing up a dedicated vector database.

CREATE VIRTUAL TABLE embeddings USING vec0(
  id INTEGER PRIMARY KEY,
  vector FLOAT[384]
);

SELECT id, distance
FROM embeddings
WHERE vector MATCH ?
ORDER BY distance
LIMIT 5;

For small datasets (under ~100k vectors) the performance is good and the operational overhead is zero. Worth a look before reaching for Qdrant or Pinecone.