Rule 7.8
Chapter 7, Expressions and statements Test
The refusals of surface §28 (a union of two GPU types, a string type, an absent literal outside the positions of Rule 7.10, a mixed tuple, a rest tuple, symbol, an intersection of carriers, instanceof, in) must apply to expressions as they do to types, each in one sentence.
T | undefined, T | null and T | null | undefined are accepted where Rule 7.10 admits them. An absent literal needs a payload type from its context; null or undefined alone is not a payload type (change 0098).
The one string an expression may be is a string literal written as an argument of a console call: it is a label, which the host keeps and the event carries in its place, and it never reaches a target (surface §66).
A template with a value in it is refused there with the arguments to write instead.
A string literal written where a key type is expected (Rule 4.1) is a member of it and stands for its id: an initializer, an assignment, an argument, a return, an operand of === or !== beside a value of the key type, and a case of a switch over one (change 0081).
A string literal that is none of the members is refused there, and string itself stays refused.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
see Rule 4.5; a label is text a human reads, which belongs on the host, and a console call is the one place the host receives it.
Derives from
surface §28 and §66; changes/0014-gpu-console.md; Rule 7.10 and changes/0088-optional-values.md, for null and the optional value.
How it is verified
Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.
Where the rule says the compiler enforces it:
src/compiler/ts/honest-refusals.test.ts; src/compiler/ts/console.test.ts, for the label and the template, in the compiler and in the language service; src/compiler/ts/key-types.test.ts, for a key type’s members; TS8002 UNKNOWN_TYPE from the union mapping Rule 7.10 names, for an absent-only type (null alone is an absent value and no payload type. Write "T | null" for a value that may be absent: the compiler carries whether the value is there (Rule 7.10).), pinned by the test Rule 7.10 names.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:716(the design document)reqs/rules/RULE-0708.md(its traceability item)