---
title: "Rule 2.1: Sources of the surface, a TypeShade design rule"
description: "Rule 2.1 of the TypeShade language design, in Sources of the surface. Every author-facing name must come from exactly one of three sources:"
url: https://typeshade.dev/reference/rules/2-1/
language: en
---

# Rule 2.1

Chapter 2, Sources of the surface Test

Every author-facing name must come from exactly one of three sources:

- (a) WGSL, as the specification spells it: a [built-in function](https://gpuweb.github.io/gpuweb/wgsl/#builtin-functions), a [predeclared type or type-generator](https://gpuweb.github.io/gpuweb/wgsl/#predeclared-types) including the predeclared `vecNf`/`vecNi`/`vecNu` aliases, an [attribute](https://gpuweb.github.io/gpuweb/wgsl/#attributes) reached as a decorator, a [built-in value](https://gpuweb.github.io/gpuweb/wgsl/#builtin-inputs-outputs) passed as a string, or an [extension](https://gpuweb.github.io/gpuweb/wgsl/#extensions) name;
- (b) ECMAScript, as TypeScript’s standard library declares it: a literal, an operator, a statement, the declaration forms, and a type, a function, an object or a member of the standard library, with the members the compiler represents. Declared today: a member of `Math`, a method of `console`, a method `Array.prototype` has, written on an array (surface §63), the declaration forms `class`, `interface`, `enum`, and `namespace`, the standard-library declarations the ambient file restates for a `lib: []` program (`Map` and `Set` among them, with the members a kernel function’s parameter has, change 0080), and the shapes surface §14 and §28 admit;
- (c) the TypeShade extensions enumerated in §9.3 of this document, one row per name with its reason.

An attribute name with which a stage or a dispatch is written (`vertex`, `fragment`, `compute`, `workgroup_size`) is an author-facing name reached as a decorator (2.1(a)); `@compute([…])` folds WGSL’s `@compute` and `@workgroup_size` into one TypeShade spelling.

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

## Rationale

a name with a source has a meaning an author can look up; a name with no source has only the compiler’s word for what it does.

## Derives from

PR [#166](https://github.com/typeshade/typeshade/issues/166)’s body, section “A design rule this lane settled” (“No TypeShade-internal helper becomes an author-facing spelling”), and [Declaration and Scope](https://gpuweb.github.io/gpuweb/wgsl/#declaration-and-scope); `changes/0100-typescript-meaning.md` (section 2) for source (b).

## 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/core/spec-conformance/surface-names.test.ts`, which classifies every declared name against `fixtures/wgsl-names.json`, the running engine’s `Math` and `console`, and `TYPESHADE_EXTENSIONS`, and holds each method the library declares on an array to the running engine’s `Array.prototype`; and the front end, which resolves a name by what declares it and never by its spelling (proposal 0008): a name nothing declares is [`TS8022`](https://typeshade.dev/reference/errors/ts8022/) for a value and [`TS8004`](https://typeshade.dev/reference/errors/ts8004/) for a callee, in a body a call lowers and in one no call lowers alike, and [`TS8002`](https://typeshade.dev/reference/errors/ts8002/) for a type wherever it is written, the base a class or an interface extends and an argument of a WGSL generic that is a type argument of a class included, except inside the extents of `@compute([…])` or `@workgroup_size([…])`, where a name nothing declares is [`TS8037`](https://typeshade.dev/reference/errors/ts8037/), in the compiler and in the editor alike ([Rule 8.7](https://typeshade.dev/reference/rules/8-7/)), once, in the compiler and in the editor alike (TypeScript’s TS2304, TS2583, TS2584, TS2591 and TS2580 merge into it, and TS2585 for a `Map` or a `Set` read as a value, change 0080), a name the file declares is the file’s whatever it spells, ahead of a type the library declares of the name, and a declaration of the file wins over a §9.3 constant of its name, and an enum, a namespace, a class or a type the file declares, read as a value, says what it is and the value it offers, once (`TS8022`, TypeScript’s report about its `typeof` merged into it), pinned by `src/compiler/ts/host-names.test.ts` and `src/language-service/diagnostics.test.ts`; the two spellings ECMAScript’s strict mode lets no declaration bind, `eval` and `arguments`, are refused once where a variable, a parameter or a function binds one, [`TS8068`](https://typeshade.dev/reference/errors/ts8068/), as TypeScript’s TS1215 refuses them (TS1215, TS1210 and TS1100 merge into it, and so does what TypeScript says of a later write of the name), while a class, an enum, a namespace or a type of the name is the file’s, as TypeScript takes it, pinned by `src/compiler/ts/host-names.test.ts`; a `new` finds its class the same way, with what another block of a namespace exports, and a type annotation inside a namespace finds the class the `new` there builds, pinned by `src/compiler/ts/new-expression.test.ts`; the ambient library’s own types and values are names the compiler knows are declared, a type of its own says it is one where a type, a value or a callee is read (TypeScript’s TS2693 merges into it), and a shader type is none of them, pinned by `src/language-service/ambient-parity.test.ts` and `src/compiler/ts/host-names.test.ts`; and a member is looked up on its receiver, so a class field `reverse` or a method `swizzle` is the class’s, pinned by `src/compiler/ts/class-methods.test.ts`; a function a namespace of the file declares under the name `ref` is an ordinary function of the file, since the library no longer declares one ([Rule 8.25](https://typeshade.dev/reference/rules/8-25/)), pinned by `src/compiler/ts/reference-parameters.test.ts`.

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

- [`src/compiler/ts/class-methods.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-methods.test.ts#L1)
- [`src/compiler/ts/host-names.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-names.test.ts#L1)
- [`src/compiler/ts/matrix-f-aliases.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/matrix-f-aliases.test.ts#L1)
- [`src/compiler/ts/new-expression.test.ts:111`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/new-expression.test.ts#L111)
- [`src/compiler/ts/reference-parameters.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/reference-parameters.test.ts#L1)
- [`src/core/spec-conformance/surface-names.test.ts:144`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/spec-conformance/surface-names.test.ts#L144)
- [`src/language-service/ambient-parity-math-object.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-parity-math-object.test.ts#L1)
- [`src/language-service/ambient-parity.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-parity.test.ts#L1)
- [`src/language-service/diagnostics-brand-tags.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics-brand-tags.test.ts#L2)
- [`src/language-service/diagnostics-glsl-hlsl-names.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics-glsl-hlsl-names.test.ts#L2)
- [`src/language-service/diagnostics-module-variables.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics-module-variables.test.ts#L2)
- [`src/language-service/diagnostics-one-mistake.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics-one-mistake.test.ts#L2)
- [`src/language-service/diagnostics-vector-arithmetic.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics-vector-arithmetic.test.ts#L2)
- [`src/language-service/diagnostics.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics.test.ts#L2)

## Explained in

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

- [§3 Entries — stage attributes and explicit builtins](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#3-entries--stage-attributes-and-explicit-builtins)
- [§14 TypeScript shapes the parser already had](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#14-typescript-shapes-the-parser-already-had)
- [§26 Classes with methods, a constructor and static functions](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#26-classes-with-methods-a-constructor-and-static-functions)
- [§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)
- [§63 An array's methods](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#63-an-arrays-methods)
- [§77 The subgroup built-in functions: `subgroupAdd` and the twenty beside it](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#77-the-subgroup-built-in-functions-subgroupadd-and-the-twenty-beside-it)

## 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). A base that the file declares and does not collect as a struct is `STRUCT_FIELD`.

**[`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/)).

**[`TS8011`](https://typeshade.dev/reference/errors/ts8011/)**

Retired codes.

**[`TS8012`](https://typeshade.dev/reference/errors/ts8012/)**

Retired codes.

**[`TS8022`](https://typeshade.dev/reference/errors/ts8022/) `UNKNOWN_NAME`**

A reference to a name that TypeShade cannot resolve and that is not a function call (`UNKNOWN_FN`) or a type name (`UNKNOWN_TYPE`). A name that the library declares for TypeScript's own use (`Object`, `Math`, `Symbol`), or that the file declares as an enum, a namespace, a class or a type, and that is read as a value, says what it is.

**[`TS8037`](https://typeshade.dev/reference/errors/ts8037/) `WORKGROUP_ARG`**

`@compute(...)` with an argument that is not an array literal of one to three whole numbers: an object, a bare number, an identifier, or an empty or four-wide array. The check of the default limits is `WORKGROUP_SHAPE`.

**[`TS8068`](https://typeshade.dev/reference/errors/ts8068/) `RESERVED_NAME`**

`eval` or `arguments` bound by a variable, a parameter or a function, which ECMAScript's strict mode, and TypeScript with it, lets no declaration do (Rule 2.1).

## See also

- [Rule 1.8](https://typeshade.dev/reference/rules/1-8/) Test
- [Rule 2.2](https://typeshade.dev/reference/rules/2-2/) Test
- [Rule 8.7](https://typeshade.dev/reference/rules/8-7/)
- [Rule 8.25](https://typeshade.dev/reference/rules/8-25/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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