---
title: "TS8021 RETURN_SHAPE: an error code of the TypeShade compiler"
description: "TS8021 RETURN_SHAPE, an error code of the TypeShade compiler. A return of the wrong shape: a bare return where a value is required…"
url: https://typeshade.dev/reference/errors/ts8021/
language: en
---

# `TS8021`

Front-end code `RETURN_SHAPE`

A `return` of the wrong shape: a bare `return` where a value is required, a function that returns `undefined` and no value, or a compute entry with no return type annotation that returns a value.

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

```ts
"use typeshade"

function shade(x: f32): f32 {
  if (x > 0.5) {
    return
  }
  return x * 0.5
}

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, shade(uv.x), 1.)
}
```

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

**TS8021** error, line 5: Function "shade" returns `f32` but has a bare "return".

## How to fix it

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

example.shade.ts

```ts
"use typeshade"

function shade(x: f32): f32 {
  if (x > 0.5) {
    return 1.
  }
  return x * 0.5
}

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, shade(uv.x), 1.)
}
```

## The rules this enforces

**[Rule 7.10](https://typeshade.dev/reference/rules/7-10/) Test**

`T | undefined` and `T | null` are optional values.

**[Rule 8.19](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/8-17/)), each instance of a generic function ([Rule 8.9](https://typeshade.dev/reference/rules/8-9/)) and of a function that takes a function ([Rule 8.18](https://typeshade.dev/reference/rules/8-18/)), a method, a getter and a field that holds a function ([Rule 8.16](https://typeshade.dev/reference/rules/8-16/)) take the type of their first `return` with a value, the `return`s after it are typed against that type as against a written one, and one with no such `return` returns nothing.

## See also

- [Functions](https://typeshade.dev/guide/language/functions/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

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

- [`src/compiler/ts/lower/function-signature/workgroup.ts:180`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function-signature/workgroup.ts#L180)
- [`src/compiler/ts/lower/function.ts:2470`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L2470) (2 sites)
