TS8020
Front-end code FUNCTION_SHAPE
A function declaration or parameter shape that TypeShade does not support, such as a missing name or body, a rest parameter or a destructured parameter.
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 shade(x?: f32, y: f32): f32 { return (x ?? 0.5) * y}
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, shade(uv.x, uv.y), 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8020 error, line 3: "y" is required and follows the optional parameter "x": a required parameter cannot follow an optional one (TypeScript's TS1016). Write "y?: T", or move it before "x".
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
function shade(y: f32, x?: f32): f32 { return (x ?? 0.5) * y}
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, shade(uv.y, uv.x), 1.)}The rules this enforces
- Rule 7.10 Test
T | undefinedandT | nullare optional values.- Rule 8.8 Test
- An object has the identity a JavaScript object has (change 0142).
- 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 array (change 0142): the body reads its elements and its
.length, writes its elements in place, and cannot assign it whole (TS8018).
See also
Source
Where the compiler raises this code at commit af54ddad5, one line per file:
-
src/compiler/ts/lower/function-args.ts:210(2 sites) -
src/compiler/ts/lower/function-signature.ts:112(3 sites) -
src/compiler/ts/lower/function-signature/entry-refusals.ts:83(2 sites) -
src/compiler/ts/lower/function-signature/parameters.ts:56(8 sites) -
src/compiler/ts/lower/function-types.ts:76 -
src/compiler/ts/lower/function.ts:300(4 sites) -
src/compiler/ts/lower/local-functions.ts:83(2 sites) -
src/compiler/ts/lower/runtime-array.ts:49 -
src/compiler/ts/semantic.ts:304