TS8002
On this page

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

example.shade.ts
"use typeshade"
function shade(x: float): f32 {
return x * 0.5
}
@fragment
export 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.

example.shade.ts
"use typeshade"
function shade(x: f32): f32 {
return x * 0.5
}
@fragment
export 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
number and boolean must not be written as shader types; a number on the GPU has a width, and the boolean is spelled bool.
Rule 4.8 Test
Every matCxR with C and R in 2, 3, 4 must be a type, and a square one must also answer to matN.
Rule 6.2 Test
A storage binding’s access mode is its second type argument: storage<T> is var<storage, read> and storage<T, "read_write"> is var<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 return with a value, the returns after it are typed against that type as against a written one, and one with no such return returns 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

TS8010 STRUCT_FIELD
An invalid struct field or declaration shape.

Source

Where the compiler raises this code at commit 26de7be8, one line per file:

Edit this page Report a problem