---
title: "Rule 8.16: Functions and entry points in TypeShade"
description: "Rule 8.16 of the TypeShade language design, in Functions and entry points."
url: https://typeshade.dev/reference/rules/8-16/
language: en
---

# Rule 8.16

Chapter 8, Functions and entry points Test

An instance field that holds an arrow function or a function expression is a method of its class under the field’s name: the function’s parameters, return type and body are the method’s, an expression body is the value it returns, and `this` in it is the object, as it is in TypeScript. With no return type written, it returns what its body does, and an expression body that is an assignment, `++` or `--` runs as a statement ([Rule 8.19](https://typeshade.dev/reference/rules/8-19/)). A static field that holds a function, a function with type parameters, and an `async` or generator function must be refused with the remedy. A member a class that extends declares again must keep the kind the class above gives it, as TypeScript requires (a field, a method or an accessor, a field that holds a function standing where a method was and a field where an abstract accessor was), and `super.f` on a field that holds a function must be refused; so must an accessor over an abstract field, which TypeScript takes and which a struct here cannot mean.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

## Rationale

`onHit = (d: f32): f32 => d * this.k` is how TypeScript code often writes a method, to keep `this` bound; a shader has no function value to hand anywhere, so the one thing such a field can be is the method it is written as, called as `o.onHit(d)`, and `this` is the object in both. A static one binds `this` to the class that declares it where a static method binds it to the class the call names ([Rule 8.13](https://typeshade.dev/reference/rules/8-13/)), so it is written as the static method it means; type parameters need a generic function. TypeScript refuses a member that changes kind in a class that extends, and without the check each such program compiled to the derived class’s member where TypeScript’s object holds the base’s; a field is the object’s own, so `super` does not reach one. An abstract field is laid out in every struct below the class that declares it, so a body that class wrote reads the member and never an accessor a class below declares, 0 where TypeScript computes the getter; `abstract get f(): T` says the same thing and reaches the accessor.

## Derives from

ECMAScript [class field definitions](https://tc39.es/ecma262/#sec-classfielddefinition-record-specification-type) and [arrow functions](https://tc39.es/ecma262/#sec-arrow-function-definitions) (`this` is the object the field initializer runs for); TypeScript’s override checks (TS2416, TS2423, TS2425, TS2426, TS2610, TS2611) and TS2855 (`super` on a field); [Rule 8.9](https://typeshade.dev/reference/rules/8-9/); [Rule 8.13](https://typeshade.dev/reference/rules/8-13/); surface §26.

## How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

`TS8035 CLASS_MEMBER` for each refusal (`A static field holding a function is a static method: write "static f(...) { ... }".`; `"B.f" is a method, and the "A.f" it overrides is a field that holds a function; TypeScript refuses an override of another kind. Declare it as a field that holds a function, or rename it.`; `"super.f" names a field that holds a function, and a field is the object's own, which "super" does not reach. Declare "A.f" as a method, or write "this.f".`), pinned by `src/compiler/ts/class-syntax.test.ts` and `src/compiler/ts/class-methods.test.ts`, which also hold the three CPU paths to one value for a field that holds a function, an override of one, and a method a field overrides; `examples/gallery/class-parts/class-parts.shade.ts` in the compile gate.

The files that verify it at commit af54ddad5, each at the first line that names the rule:

- [`examples/shade-examples.test.ts:27`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/shade-examples.test.ts#L27)
- [`src/compiler/ts/class-methods.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-methods.test.ts#L1)
- [`src/compiler/ts/class-syntax.test.ts:1627`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-syntax.test.ts#L1627)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§26 Classes with methods, a constructor and static functions](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#26-classes-with-methods-a-constructor-and-static-functions)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8035`](https://typeshade.dev/reference/errors/ts8035/) `CLASS_MEMBER`**

A class member shape that the surface does not take, a use of a member that the class rules refuse, or a `new` that builds no class ([Rule 8.13](https://typeshade.dev/reference/rules/8-13/)). Getters and setters, static fields and methods, overload signatures, abstract members, `#` private names and methods that change their object all compile. The message names the member or the target and the edit.

## See also

- [Rule 8.15](https://typeshade.dev/reference/rules/8-15/) Test
- [Rule 8.17](https://typeshade.dev/reference/rules/8-17/) Test
- [Rule 8.9](https://typeshade.dev/reference/rules/8-9/)
- [Rule 8.13](https://typeshade.dev/reference/rules/8-13/)
- [Rule 8.19](https://typeshade.dev/reference/rules/8-19/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:972`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L972) (the design document)
- [`reqs/rules/RULE-0816.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0816.md) (its traceability item)
