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), a read of an optional value (T | undefined, T | null or T | null | undefined) that no test narrowed (Rule 7.10), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, an f32 past its range or a builtin call outside its domain, such as Math.pow(-2., 2.).
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"function gain(value: f32 | null | undefined): f32 { return value * 2.}@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, gain(null), 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8003 error, line 3: "value" is "f32 | null | undefined" here, and "*" takes an f32. Test it first, "if (value != null)", or give the absent case a value, "value ?? 0.".
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"function gain(value: f32 | null | undefined): f32 { if (value == null) { return 0. } return value * 2.}@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, gain(null), 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
f64and the twof32halves that carry it across an interface off32. - Rule 4.8 Test
- Every
matCxRwithCandRin 2, 3, 4 must be a type, and a square one must also answer tomatN. - Rule 5.3 Test
- There is no implicit conversion between concrete types; an
i32beside au32, 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;
-1in au32position and2147483648in ani32position are refused as written. - Rule 6.3 Test
- A top-level
constis 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 6.6 Test
- An entry point’s inputs and outputs are explicit parameters and return values.
- 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
forloop means what it means in TypeScript: its initializer runs once, its condition (truewhen it has none) is tested before each trip, and its update runs after each trip and at eachcontinue(change 0136). - Rule 7.10 Test
T | undefinedandT | nullare optional values.- 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.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
f64operands
Source
Where the compiler raises this code at commit af54ddad5, one line per file:
-
src/compiler/ts/abstract-const.ts:713(8 sites) -
src/compiler/ts/builtin-check.ts:341(4 sites) -
src/compiler/ts/builtin-type-form.ts:98 -
src/compiler/ts/internal-ops.ts:73 -
src/compiler/ts/lit-coerce.ts:713 -
src/compiler/ts/lower/array-constructor/from.ts:181 -
src/compiler/ts/lower/array-constructor/lower.ts:111 -
src/compiler/ts/lower/array-constructor/lowering.ts:42 -
src/compiler/ts/lower/array-methods.ts:66(3 sites) -
src/compiler/ts/lower/array-methods/named-function.ts:31(4 sites) -
src/compiler/ts/lower/array-methods/value-methods.ts:37(2 sites) -
src/compiler/ts/lower/atomics.ts:71(5 sites) -
src/compiler/ts/lower/barriers.ts:82 -
src/compiler/ts/lower/class-methods/construct.ts:125 -
src/compiler/ts/lower/collections.ts:95(2 sites) -
src/compiler/ts/lower/const-call.ts:47(2 sites) -
src/compiler/ts/lower/control.ts:166(2 sites) -
src/compiler/ts/lower/control/for-header.ts:225 -
src/compiler/ts/lower/control/for-of.ts:61 -
src/compiler/ts/lower/control/switch.ts:32 -
src/compiler/ts/lower/control/while.ts:22(2 sites) -
src/compiler/ts/lower/expression-array.ts:121(3 sites) -
src/compiler/ts/lower/expression-array/element.ts:37 -
src/compiler/ts/lower/expression-array/fold.ts:98(3 sites) -
src/compiler/ts/lower/expression-array/list-uses.ts:20 -
src/compiler/ts/lower/expression-call.ts:154(8 sites) -
src/compiler/ts/lower/expression-call/args.ts:135 -
src/compiler/ts/lower/expression-call/bit-builtins.ts:70(5 sites) -
src/compiler/ts/lower/expression-call/gather.ts:30(6 sites) -
src/compiler/ts/lower/expression-call/matrix-ctor.ts:70(3 sites) -
src/compiler/ts/lower/expression-call/multisampled.ts:59(2 sites) -
src/compiler/ts/lower/expression-call/select-and-reduce.ts:111(5 sites) -
src/compiler/ts/lower/expression-call/storage-depth.ts:48(8 sites) -
src/compiler/ts/lower/expression-call/texture-call.ts:39(7 sites) -
src/compiler/ts/lower/expression-misc.ts:168 -
src/compiler/ts/lower/expression-misc/scalar-calls.ts:93(3 sites) -
src/compiler/ts/lower/expression-prop/object-literal.ts:166(4 sites) -
src/compiler/ts/lower/expression.ts:150(27 sites) -
src/compiler/ts/lower/expression/key-operands.ts:32(3 sites) -
src/compiler/ts/lower/expression/kindless-division.ts:58(4 sites) -
src/compiler/ts/lower/expression/operand-reads.ts:108 -
src/compiler/ts/lower/for-step-fit.ts:44(2 sites) -
src/compiler/ts/lower/function-args.ts:129(5 sites) -
src/compiler/ts/lower/function.ts:2175(3 sites) -
src/compiler/ts/lower/index-select.ts:74(9 sites) -
src/compiler/ts/lower/made-array/lower.ts:230 -
src/compiler/ts/lower/operator-kinds.ts:163(3 sites) -
src/compiler/ts/lower/optional-values/diagnostic.ts:11 -
src/compiler/ts/lower/statement/assign.ts:141(3 sites) -
src/compiler/ts/lower/statement/binding-pattern.ts:74 -
src/compiler/ts/lower/statement/bitwise-assign.ts:102(5 sites) -
src/compiler/ts/lower/statement/branch.ts:33(2 sites) -
src/compiler/ts/lower/statement/compound-assign.ts:122(5 sites) -
src/compiler/ts/lower/statement/declaration-kind.ts:109(4 sites) -
src/compiler/ts/lower/subgroups.ts:82(2 sites) -
src/compiler/ts/module-const.ts:145(14 sites) -
src/compiler/ts/module-vars/inferred-value.ts:16 -
src/compiler/ts/remedies/validate.ts:75(2 sites) -
src/compiler/ts/structs/field-shapes.ts:83 -
src/language-service/check.ts:226 -
src/language-service/diagnostics.ts:78(2 sites) -
src/language-service/diagnostics/refused-attributes.ts:142 -
src/language-service/diagnostics/refused-list.ts:28 -
src/language-service/service.ts:199