TS8002
Front-end code UNKNOWN_TYPE
A type name nothing declares, said once for the file wherever it is written (a parameter, a claim, a type argument, B<vec3<Foo>> included, an alias, an implements clause, the base a class or an interface extends, a body no call lowers), a type the library declares for TypeScript alone (Number) where the file declares none of its name, or a type this surface does not take in a position the mapper reads (Rule 2.1).
The registry text and every compiler message on these pages are the compiler's own English.
When it fires
A type name nothing declares, said once for the file wherever it is written (a parameter, a claim, a type argument, B<vec3<Foo>> included, an alias, an implements clause, the base a class or an interface extends, a body no call lowers), a type the library declares for TypeScript alone (Number) where the file declares none of its name, or a type this surface does not take in a position the mapper reads (Rule 2.1). A base the file declares and does not collect as a struct is the struct collector's, STRUCT_FIELD.
Example
"use typeshade"
function shade(x: float): f32 { return x * 0.5}
@fragmentexport function main(@location(0) uv: vec2): vec4 { return vec4(uv, shade(uv.x), 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8002 error, line 3: Unknown type "float". GLSL's and HLSL's float is f32 here.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
function shade(x: f32): f32 { return x * 0.5}
@fragmentexport function main(@location(0) uv: vec2): vec4 { return vec4(uv, shade(uv.x), 1.)}The rules this enforces
- Rule 2.1 Test
- Every author-facing name must come from exactly one of three sources:
- Rule 4.1 Test
- Every type an author writes must be a WGSL type under a TypeScript spelling, or a member of the f64 family (Rule 4.4).
- Rule 4.6 Test
numberandbooleanmust not be written as shader types; a number on the GPU has a width, and the boolean is spelledbool.- Rule 4.8 Test
- Every
matCxRwithCandRin 2, 3, 4 must be a type, and a square one must also answer tomatN. - Rule 6.2 Test
- A storage binding’s access mode is its second type argument:
storage<T>isvar<storage, read>andstorage<T, "read_write">isvar<storage, read_write>. - Rule 8.18 Test
- A function whose parameter has a function type, written out (
f: (x: f32) => f32) or through a type alias of one, takes a function: a function declared at the top of the file or of a namespace, a method, a static method, a constructor, a field that holds a function (Rule 8.16) and a local function (Rule 8.17). - Rule 8.19 Test
- A function that writes no return type returns what its body does, as TypeScript infers it: a function of the file or of a namespace, a local function (Rule 8.17), each instance of a generic function (Rule 8.9) and of a function that takes a function (Rule 8.18), a method, a getter and a field that holds a function (Rule 8.16) take the type of their first
returnwith a value, thereturns after it are typed against that type as against a written one, and one with no suchreturnreturns nothing. - Rule 12.4 Test
- One mistake reads as one diagnostic; a refusal must not be followed by further diagnostics about the same mistake.
- Rule 12.6 Test
- A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.
See also
-
TS8010STRUCT_FIELD - An invalid struct field or declaration shape.
Source
Where the compiler raises this code at commit 26de7be8, one line per file:
-
src/compiler/ts/bindings.ts:240(3 sites) -
src/compiler/ts/generic-structs.ts:155 -
src/compiler/ts/generics.ts:147 -
src/compiler/ts/lower/expression-array.ts:92(4 sites) -
src/compiler/ts/lower/expression-call.ts:537 -
src/compiler/ts/lower/function.ts:671(4 sites) -
src/compiler/ts/lower/statement.ts:560 -
src/compiler/ts/module-const.ts:665 -
src/compiler/ts/semantic.ts:152 -
src/compiler/ts/source-file.ts:481 -
src/compiler/ts/type-map.ts:1235(5 sites)