// Direct annotation — the right-hand side must satisfy the structure:
const ethanol: Smiles<"CCO"> = "CCO"; // ok
const benzene: Smiles<"c1ccccc1"> = "c1ccccc1"; // ok
const broken: Smiles<"CC(=O"> = "CC(=O"; // error: Type '"CC(=O"' is not assignable to type 'never'
// As a function constraint that brands only valid SMILES literals:
declare function asSmiles<S extends string>(value: Smiles<S>): S;
const a = asSmiles("CC(=O)O"); // type: "CC(=O)O"
const b = asSmiles("CC(=O"); // error at the call site
// As a per-element constraint over a const array:
type SmilesList<T extends readonly string[]> = { [K in keyof T]: Smiles<T[K]> };
declare function smilesList<const T extends readonly string[]>(list: SmilesList<T>): T;
const lib = smilesList(["CCO", "CC(=O)O", "c1ccccc1"]); // ok
Resolves to
Sitself whenSis a structurally-plausible SMILES string, otherwisenever. Mirrors the spirit of theCAS<T>type in cas.d.ts: a literal in, a constrained literal out.