TS8010
Front-end code 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).
The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.
The registry text and every compiler message on these pages are the compiler's own English.
Example
"use typeshade"
class Tint { rgb: vec3 alpha: f32}
function tint(uv: vec2): Tint { return { rgb: vec3(uv, 0.) }}
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(tint(uv).rgb, 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8010 error, line 9: Missing field "alpha" for struct Tint.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
class Tint { rgb: vec3 alpha: f32}
function tint(uv: vec2): Tint { return { rgb: vec3(uv, 0.), alpha: 1. }}
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(tint(uv).rgb, 1.)}The rules this enforces
- Rule 6.6 Test
- An entry point’s inputs and outputs are explicit parameters and return values.
- Rule 6.8 Test
- The byte layout the emitted module assumes for a resource and the layout
reflect()reports must agree byte for byte, under WGSL’s uniform and storage layout rules, and so must the layout the manifest carries (Rule 11.10); a vertex entry’s vertex buffer is one layout, its@locationinputs tightly packed in the order written and numbered in that order where nolocation<n, T>states the number (Rule 6.6), whichreflect().vertexand the manifest both report. - Rule 6.9 Test
- A struct must be the members written in it, in one of four spellings (
class,interface, atypeover an object literal, an object type literal written where a type stands). - Rule 8.12 Test
- A private name
#xmust be emitted without its#: a field as the struct memberx, a method asOwner_x, an accessor asOwner_get_xandOwner_set_x, a static field asOwner_x. - Rule 8.14 Test
- A constructor’s parameter property (
constructor(public x: f32), orprivate,protectedorreadonlyin place ofpublic) is a field of its class, at the constructor’s place among the members, which the constructor assigns from the parameter before the field initializers run. - Rule 8.15 Test
- A member declared
privatemay be named only inside the body of the class that declares it, and one declaredprotectedonly inside the bodies of that class and of the classes that extend it, on an object of the naming body’s own class or of one that extends it; a name either rule does not allow must be refused with the remedy.
See also
-
SD0020 - module validation failed
Source
Where the compiler raises this code at commit af54ddad5, one line per file:
-
src/compiler/ts/entry-locations.ts:69 -
src/compiler/ts/lower/expression-prop/object-literal.ts:74(5 sites) -
src/compiler/ts/lower/function-signature/parameters.ts:316 -
src/compiler/ts/source-file.ts:383 -
src/compiler/ts/structs/diagnostics.ts:11 -
src/compiler/ts/structs/entry-io.ts:186(2 sites) -
src/language-service/diagnostics/refusal-tables.ts:10