Rule 6.9
On this page

Rule 6.9

Chapter 6, Declarations and resources Test

A struct must be the members written in it, in one of three spellings (class, interface, a type over an object literal). On a class or an interface with an extends clause it must be the base’s members first and its own after, through a chain of any depth. A class’s members include the fields its constructor’s parameter properties declare, and a field written without a type takes the one its initializer names (Rule 8.14). An interface that declares a method is a contract and not a struct: a class may name it in implements and a type parameter in its constraint (<T extends Shape>), and a value typed by it must be refused with the remedy, once, where the interface declares the method. A call signature, an index signature, and an optional member must be refused.

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

Rationale

a WGSL structure has no form for any of the three, and dropping one silently would change the buffer layout the host fills; a base’s members are laid out where TypeScript’s structural typing says they are, so an extends drops nothing. An interface with a method says what a class supplies, and a call through it runs the body of the class the value is, which static dispatch finds through that class or through the type parameter a call binds (Rule 8.9); a value of the interface’s own type would have to pick the body at run time, which a WGSL function cannot.

Derives from

Structure Types; TypeScript’s implements clauses and generic constraints; surface §2; surface §26 (“extends, abstract and implements”, roadmap 0.3 item T5, #92; “An interface with methods is a contract”).

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:

TS8010 STRUCT_FIELD, pinned by src/compiler/ts/type-structs.test.ts (a method signature on an interface a value is typed by, "Bad" declares a method, so it is a contract a class implements and not a value a shader holds: take the class that implements it, or a type parameter it constrains, "<T extends Bad>(v: T)".; a call signature, an index signature, an optional field); src/compiler/ts/class-syntax.test.ts for a contract in implements and in a constraint, held to one value on every CPU path, and examples/class-parts.shade.ts in the compile gate; src/compiler/ts/inheritance.test.ts (a derived struct is its base plus its own) for the layout.

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

Explained in

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

Error codes that enforce it

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

TS8010 STRUCT_FIELD
An invalid struct field or declaration shape.

See also

Source

The rule at commit 26de7be8:

Edit this page Report a problem