---
title: "Rule 4.2, Types: a TypeShade language design rule"
description: "Rule 4.2 of the TypeShade language design, in Types. A type alias is another name for its target."
url: https://typeshade.dev/reference/rules/4-2/
language: en
---

# Rule 4.2

Chapter 4, Types Test

A type alias is another name for its target. An alias of a scalar, a vector, an array, or a struct must resolve wherever a type may stand, and an alias, an interface, or a class over an object type is one struct. An object type literal written where a type stands (a parameter, a result, a local, a field, an array element, a type argument, the argument of `uniform<…>` or `storage<…>`) is one struct for each set of field names and types, whatever the order of the fields. A literal and a named struct of the same field set are one struct. A builtin type name must win over an alias of the same name, so `type vec3 = f32` does not make `vec3` a scalar.

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

## Rationale

the first two clauses are what a type alias means in TypeScript and in WGSL alike. The third is a recorded divergence from WGSL, where a module-scope declaration hides the predeclared object of the same name. It is kept because a file that re-types a builtin name would make every later use of that name mean something no reader of the surface can see.

## Derives from

[Type Aliases](https://gpuweb.github.io/gpuweb/wgsl/#type-aliases) for the resolution; surface §2 (roadmap 0.3 item T2) for the precedence, which reverses [Declaration and Scope](https://gpuweb.github.io/gpuweb/wgsl/#declaration-and-scope) (“predeclared objects, and objects declared at module-scope, are in scope across the entire program source”, and the example “Shadowing predeclared objects”, where a module-scope `fn min()` hides the builtin).

## 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/type-alias.test.ts` (resolution, and “an alias cannot shadow a builtin name”) and `TS8023 DUPLICATE_SYMBOL` for a second declaration of one struct name, whether or not anything uses the struct ([#172](https://github.com/typeshade/typeshade/issues/172)), pinned by `src/compiler/ts/type-structs.test.ts`.

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

- [`src/compiler/ts/type-alias.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-alias.test.ts#L1)
- [`src/compiler/ts/type-map/shapes.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-map/shapes.test.ts#L1)
- [`src/compiler/ts/type-structs.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-structs.test.ts#L1)

## Explained in

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

- [§2 Value types — `type`, `interface` and `class`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#2-value-types--type-interface-and-class)

## Error codes that enforce it

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

**[`TS8023`](https://typeshade.dev/reference/errors/ts8023/) `DUPLICATE_SYMBOL`**

The same function, binding, module constant or struct name declared twice in one scope. A struct counts whichever spelling each declaration uses: a class, an interface and a type alias of one name are one struct, so a second declaration is a duplicate.

## See also

- [Rule 4.1](https://typeshade.dev/reference/rules/4-1/) Test
- [Rule 4.3](https://typeshade.dev/reference/rules/4-3/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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