ChemPal Documentation - v1.6.0
    Preparing search index...

    Type Alias Smiles<S>

    Smiles: "" extends S ? never : ValidateSmiles<S> extends true ? S : never

    Resolves to S itself when S is a structurally-plausible SMILES string, otherwise never. Mirrors the spirit of the CAS<T> type in cas.d.ts: a literal in, a constrained literal out.

    Type Parameters

    • S extends string
    // 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