---
title: "Rule 6.9: Declarations and resources in TypeShade"
description: "Rule 6.9 of the TypeShade language design, in Declarations and resources."
url: https://typeshade.dev/reference/rules/6-9/
language: en
---

# Rule 6.9

Chapter 6, Declarations and resources Test

A struct must be the members written in it, in one of four spellings (`class`, `interface`, a `type` over an object literal, an object type literal written where a type stands). 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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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](https://gpuweb.github.io/gpuweb/wgsl/#struct-types); TypeScript’s [`implements` clauses](https://www.typescriptlang.org/docs/handbook/2/classes.html#implements-clauses) and [generic constraints](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints); surface §2; surface §26 (“`extends`, `abstract` and `implements`”, roadmap 0.3 item T5, [#92](https://github.com/typeshade/typeshade/issues/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/gallery/class-parts/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 af54ddad5, each at the first line that names the rule:

- [`examples/shade-examples.test.ts:26`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/shade-examples.test.ts#L26)
- [`src/compiler/ts/class-syntax.test.ts:1755`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-syntax.test.ts#L1755)
- [`src/compiler/ts/inheritance-methods.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance-methods.test.ts#L1)
- [`src/compiler/ts/inheritance-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance-refusals.test.ts#L1)
- [`src/compiler/ts/inheritance.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance.test.ts#L1)
- [`src/compiler/ts/type-structs.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-structs.test.ts#L1)

## Explained in

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

- [§2 Value types — `type`, `interface` and `class`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#2-value-types--type-interface-and-class)
- [§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)

## Error codes that enforce it

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

**[`TS8010`](https://typeshade.dev/reference/errors/ts8010/) `STRUCT_FIELD`**

An invalid struct field or declaration shape. A class with no fields is accepted; this code covers an invalid field declaration, an empty struct that is not a class, an `@align` on a field, which is not applied, and a user-defined value whose uses give it two locations ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)).

## See also

- [Rule 6.8](https://typeshade.dev/reference/rules/6-8/) Test
- [Rule 6.10](https://typeshade.dev/reference/rules/6-10/) Test
- [Rule 8.9](https://typeshade.dev/reference/rules/8-9/)
- [Rule 8.14](https://typeshade.dev/reference/rules/8-14/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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