TS8003
On this page

TS8003

Front-end code TYPE_MISMATCH

Two types that do not fit where they meet (an operator, a condition, a declaration, a return or an argument), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross or an f32 past its range.

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

example.shade.ts
"use typeshade"
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(uv + vec3(0.5, 0.5, 0.5), 1.)
}

Compiled at build time against the pinned compiler, this program gets:

TS8003 error, line 5: Type mismatch: cannot + vec2 and vec3. Vectors must have the same size.

How to fix it

The same program, corrected. It compiles with no diagnostic.

example.shade.ts
"use typeshade"
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(vec3(uv, 0.) + vec3(0.5, 0.5, 0.5), 1.)
}

The rules this enforces

Rule 2.3 Test
A value sometimes has to cross between a representation the compiler chose and one the target has: an f64 and the two f32 halves that carry it across an interface of f32.
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 5.3 Test
There is no implicit conversion between concrete types; an i32 beside a u32, or an integer beside a float, must be refused with the cast to write.
Rule 5.4 Test
A literal must fit the type it takes; -1 in a u32 position and 2147483648 in an i32 position are refused as written.
Rule 6.3 Test
A top-level const is a module constant: a scalar must fold to one value carried at double precision for the oracle and at the target’s precision for emit, and a vector, array, or struct must carry a constant-foldable expression every backend evaluates.
Rule 7.1 Test
An operator, a swizzle, an index, and a call must mean what WGSL’s typing table gives them.
Rule 7.4 Test
A shift amount the compiler can fold must be in 0 to 31; a divisor the compiler can prove to be zero must be refused where the division is lowered.
Rule 7.5 Test
A for loop must be counted: an i32 or u32 induction variable, a constant step, and an exit that compares the induction variable to a bound; the start and the bound may be runtime values, the loop body must not write the bound, and the step must move the variable toward the bound.
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.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

SD0001
matrix × vector size mismatch
SD0002
binary op on mismatched vectors
SD0003
arithmetic op on a bool operand
SD0004
binary op on incompatible types
SD0009
.select() on a non-bool condition
SD0010
select branches have differing types
SD0017
literal cannot be spelled by the target
SD0041
unsupported operation on f64 operands

Source

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

Edit this page Report a problem