Escapes a string for embedding in a TypeScript double-quoted string
literal. pub because bynk-emit’s escape_ts_string (~65 call sites
across the emitter’s real emission code) delegates here rather than
keeping its own copy — the two must stay byte-identical since both
splice into generated TypeScript, so this is the one shared definition.
Events slice 3a (#972): the wire-form JSON literal an event field’s
default deserialises from when its key is absent from the incoming JSON.
Type-directed — given the field’s expected TypeRef and the visible
types table, every syntactic ambiguity (a bare Ident that is really a
sum variant, a FieldAccess that is a qualified nullary variant) resolves
the same way the checker resolves it, just narrower (a bare name must
match a variant of this expected sum specifically) — so this needs no
per-expression Ty map (expr_types), which a subscriber regenerating a
publisher’s own event codec (emit_consumed_context_helpers) has no way
to obtain anyway (no cross-unit expr_types store exists).