---
title: "Rule 7.8: Expressions and statements in TypeShade"
description: "Rule 7.8 of the TypeShade language design, in Expressions and statements."
url: https://typeshade.dev/reference/rules/7-8/
language: en
---

# 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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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:

- [`src/compiler/ts/console.test.ts:60`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/console.test.ts#L60)
- [`src/compiler/ts/honest-refusals-tuples.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals-tuples.test.ts#L1)
- [`src/compiler/ts/honest-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals.test.ts#L1)
- [`src/compiler/ts/key-types.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/key-types.test.ts#L2)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§28 What TypeScript writes that the GPU has no word for](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#28-what-typescript-writes-that-the-gpu-has-no-word-for)
- [§66 `console`: what reaches the host](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#66-console-what-reaches-the-host)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8002`](https://typeshade.dev/reference/errors/ts8002/) `UNKNOWN_TYPE`**

A type name that nothing declares, in a parameter, a type argument, an alias, an `implements` clause or a base class, or a type that this surface does not take where the mapper reads one ([Rule 2.1](https://typeshade.dev/reference/rules/2-1/)). A base that the file declares and does not collect as a struct is `STRUCT_FIELD`.

## See also

- [Rule 7.7](https://typeshade.dev/reference/rules/7-7/) Test
- [Rule 7.9](https://typeshade.dev/reference/rules/7-9/) Test
- [Rule 4.1](https://typeshade.dev/reference/rules/4-1/)
- [Rule 4.5](https://typeshade.dev/reference/rules/4-5/)
- [Rule 7.10](https://typeshade.dev/reference/rules/7-10/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:716`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L716) (the design document)
- [`reqs/rules/RULE-0708.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0708.md) (its traceability item)
