Skip to content

brand-sink ​

A member the project (or a pack) declared to take only a brand of its own, given anything else: brandSinks("Sql", ["pg Pool#query"]) makes pool.query(text) with a plain string a finding, as a string given to innerHTML is. Also a brandSinks call whose brand or members the source doesn't show.

Why: a brand is a fact the type carries (this SQL came from the tagged template, this id from the parser), and TypeScript holds every function typed with it to it. A library's own function takes a string, so TypeScript can't: the declaration tells the checker which members take the brand, and the checker refuses the rest, constants included, since a constant isn't what the constructor makes either.

✕ Rejectedbrand-sink
ts
import { DatabaseSync } from "node:sqlite";

import { type Brand, brandConstructor, brandSinks } from "@evobug_com/safe-ts-std/brand";
import { unsafe } from "@evobug_com/safe-ts-std/result";

export type Sql = Brand<"Sql">;
export const sql = brandConstructor("Sql", (parts: TemplateStringsArray, ..._values: readonly number[]): string => parts.join("?"));
brandSinks("Sql", ["node:sqlite Database#prepare"]);

export function count(db: DatabaseSync, table: string): unknown {
  return unsafe(() => db.prepare(`SELECT count(*) FROM ${table}`).get());
}

✅ Accepted: what the constructor made

✓ Accepted0 diagnostics
ts
import { DatabaseSync } from "node:sqlite";

import { type Brand, brandConstructor, brandSinks } from "@evobug_com/safe-ts-std/brand";
import { unsafe } from "@evobug_com/safe-ts-std/result";

export type Sql = Brand<"Sql">;
export const sql = brandConstructor("Sql", (parts: TemplateStringsArray, ..._values: readonly number[]): string => parts.join("?"));
brandSinks("Sql", ["node:sqlite Database#prepare"]);

export function countUsers(db: DatabaseSync, minimum: number): unknown {
  return unsafe(() => db.prepare(sql`SELECT count(*) FROM users WHERE logins >= ${minimum}`).get(minimum));
}

A member is written as the maps write it: "module member" for a function ("pg query"), a class's method as "module Class#method" ("pg Pool#query", "node:sqlite Database#prepare"), a global's as "Class#method" ("Window#open"). The brand is taken at the first argument. A declared member replaces what the platform's map says of it (Database#prepare is an sql-sink otherwise). The worked examples are in Proof types: brands of your own.

What the rule can't see: in the editor, only the brandSinks of the modules the file imports, directly or not (a file that uses a brand imports the module that declares it); safe-ts check reads every file's. A receiver whose class the checker can't tell (a value from a function of yours that returns the client untyped): declare its type (db: Pool).

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra