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

# Rule 7.7

Chapter 7, Expressions and statements Test

`discard` must be written as a bare statement, the identifier alone (`discard`), and may stand in a fragment entry and in a helper no vertex or compute entry can reach. The check closes over the call graph, and `discard()` is not a call the surface has.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

## Rationale

WGSL’s `discard` is a statement of the fragment stage; TypeScript has no statement to borrow, so the ambient library declares `discard` as a constant of type `void` (§9.3, family 5) and the compiler lowers an expression statement that is exactly that identifier to the statement, with the stage rule kept.

## Derives from

[Discard Statement](https://gpuweb.github.io/gpuweb/wgsl/#discard-statement) (“must only be used in a fragment shader stage”); surface §10; `declare const discard: void` in `src/language-service/ambient.ts`.

## 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/builtins.test.ts` (`discard`: lowers to the discard statement, emits it on both targets); [`TS8099`](https://typeshade.dev/reference/errors/ts8099/) names the entry, or the helper and the entry, on the wrong stage; `discard()` is [`TS8004`](https://typeshade.dev/reference/errors/ts8004/), which says that `discard` is a statement and is written without the parentheses (`src/compiler/ts/unknown-names.test.ts`).

The files that verify it at commit af54ddad5, each at the first line that names the rule:

- [`src/compiler/ts/builtins.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtins.test.ts#L1)
- [`src/compiler/ts/unknown-names.test.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/unknown-names.test.ts#L3)

## Explained in

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

- [§10 Builtins, casts and `discard`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#10-builtins-casts-and-discard)

## Error codes that enforce it

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

**[`TS8004`](https://typeshade.dev/reference/errors/ts8004/) `UNKNOWN_FN`**

A call to a function the file neither declares nor imports, or to a builtin the language removed because ECMAScript spells it, such as `arrayLength(xs)`, whose message names `xs.length` ([Rule 9.9](https://typeshade.dev/reference/rules/9-9/)).

**[`TS8099`](https://typeshade.dev/reference/errors/ts8099/) `UNSUPPORTED`**

The catch-all for a diagnostic whose site does not yet deserve its own code. It stays parked at TS8099, past the sequential range.

## See also

- [Rule 7.6](https://typeshade.dev/reference/rules/7-6/) Test
- [Rule 7.8](https://typeshade.dev/reference/rules/7-8/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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