---
title: "Rule 4.6, Types: a TypeShade language design rule"
description: "Rule 4.6 of the TypeShade language design, in Types. boolean written as a type must mean bool…"
url: https://typeshade.dev/reference/rules/4-6/
language: en
---

# Rule 4.6

Chapter 4, Types Test

`boolean` written as a type must mean `bool`, and `number` written as a type must mean that the type is inferred from its uses (OD-7); where no use decides, the type must be `f32`. Where TypeScript lets an annotation be omitted (a local, a result, a field, a list’s element, a parameter), `number` must read as if it were omitted, and an unannotated parameter, with or without a default, must mean the same as one written `number`. `f32`, `i32`, `u32` and `f64` must keep fixing a width. A parameter’s width must come from the places that call the function:

1. One call site, or call sites of one width: the parameter has the width of the values the calls pass.
2. Call sites of different widths: the function is compiled once for each set of widths the calls use, as a generic function is ([Rule 8.9](https://typeshade.dev/reference/rules/8-9/), [Rule 3.9](https://typeshade.dev/reference/rules/3-9/)); no call is refused for its width.
3. No call site: the parameter is `f32`.
4. An exported function: a call of it from any file of the program (Rule 3.9) is a call site and rules 1 to 3 apply; a call from outside the program is not read. A parameter of an entry point or a kernel function is inferred from the uses in its body only, and is `f32` where none decides.
5. A recursive function: the width of a parameter of a call cycle is the width the calls from outside the cycle pass, and the calls inside the cycle must agree with it or the cycle is compiled once for each such width (recursion itself stays under [Rule 8.4](https://typeshade.dev/reference/rules/8-4/)).
6. A value whose uses in one function demand two widths, and a `number` that one use makes an integer and that `/` divides, must be refused as [Rule 5.1](https://typeshade.dev/reference/rules/5-1/) refuses them.

A struct field, a class field and a field of a uniform or storage struct that is written `number` is decided from the places that assign or read it, and is `f32` where none decides.

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

## Rationale

TypeScript accepts `number` and `boolean` (OD-12), and OD-7 removed the argument that `number` names no width: the compiler infers the width and chooses `f32` where no use decides.

## Derives from

[Integer Types](https://gpuweb.github.io/gpuweb/wgsl/#integer-types), [Floating Point Types](https://gpuweb.github.io/gpuweb/wgsl/#floating-point-types), [Boolean Type](https://gpuweb.github.io/gpuweb/wgsl/#bool-type); `changes/0159-number-and-boolean-written-as-types.md`.

## 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:

`src/compiler/ts/number-types.test.ts`.

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

- [`src/compiler/ts/honest-refusals-tuples.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals-tuples.test.ts#L1)
- [`src/compiler/ts/honest-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals.test.ts#L1)
- [`src/compiler/ts/number-types.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/number-types.test.ts#L1)

## Explained in

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

- [§28 What TypeScript writes that the GPU has no word for](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#28-what-typescript-writes-that-the-gpu-has-no-word-for)

## See also

- [Rule 4.5](https://typeshade.dev/reference/rules/4-5/) Test
- [Rule 4.7](https://typeshade.dev/reference/rules/4-7/) Test
- [Rule 3.9](https://typeshade.dev/reference/rules/3-9/)
- [Rule 5.1](https://typeshade.dev/reference/rules/5-1/)
- [Rule 8.4](https://typeshade.dev/reference/rules/8-4/)
- [Rule 8.9](https://typeshade.dev/reference/rules/8-9/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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