Rule 4.1
On this page

Rule 4.1

Chapter 4, Types Test

Every type an author writes must be a type borrowed from WGSL under a TypeScript spelling, a member of the f64 family (Rule 4.4), a key type, or a type ECMAScript defines that the compiler represents (Rule 1.5). A union of string literal types, or one string literal type, is a key type (change 0081): a u32 under that spelling, whose members are its values, each held as its id, the member’s index in the order of the members’ UTF-16 code units. A key type takes ===, !== and switch over its members, and no other operator; a value of another key type, or a number, is no value of it. Record<K, V> with K a key type is an array<V, N>, N the number of members, indexed by the member’s id (change 0081): r[k] with k of the key type, r.g and r["g"] the constant index of "g", and an object literal with one value for each member, in any order, its value.

Record<K, V> also takes an enum or a union of integer literals when its distinct values are exactly 0 through N-1, indexed by the member value; other numeric domains are refused with their actual values (change 0081, decision 2).

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

Rationale

the layout, the constructors, and the builtins of a type borrowed from WGSL are WGSL’s, and a type WGSL does not have has none of those; a type ECMAScript defines keeps ECMAScript’s meaning and takes the representation the compiler chooses (Rule 1.5), as Map and Set do (change 0080).

Derives from

changes/0100-typescript-meaning.md (section 2); Types, Plain Types and Texture and Sampler Types.

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:

SUPPORTED_TYPE_NAMES in src/compiler/ts/type-map.ts (TS8002 UNKNOWN_TYPE names the whole list) and surface-names.test.ts for the spellings; keyTypeT in src/compiler/ts/key-types.ts and src/compiler/ts/key-types.test.ts for the key types, in the compiler and in the language service.

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:

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.

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem