TS8020
Front-end code FUNCTION_SHAPE
A function declaration or parameter shape TypeShade does not support (missing name or body, optional/rest/destructured parameter).
The registry text and every compiler message on these pages are the compiler's own English.
Example
"use typeshade"
function shade(x?: f32): f32 { return 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:
TS8020 error, line 3: Optional parameter "x" is not supported: a shader value is always present, so there is no "absent" for the body to test. Give it a default instead, "x: T = ...", which a call that omits it fills in.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
function shade(x: f32 = 0.5): f32 { return x}
@fragmentexport function main(@location(0) uv: vec2): vec4 { return vec4(uv, shade(uv.x), 1.)}The rules this enforces
- Rule 8.8 Test
- A parameter an author writes must be passed by value; there must be no pointers and no reference parameters.
- 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 8.23 Test
- A kernel function’s parameter of an array with no size is the caller’s storage, passed by reference: the body reads and writes its elements in place, reads its
.length, and cannot assign it whole; whether the body writes it decides its access.
See also
Source
Where the compiler raises this code at commit 26de7be8, one line per file: