---
title: "Rule 3.1: Textual structure and names in TypeShade"
description: "Rule 3.1 of the TypeShade language design, in Textual structure and names. A shader file must begin with the directive \"use typeshade\" as its first statement."
url: https://typeshade.dev/reference/rules/3-1/
language: en
---

# Rule 3.1

Chapter 3, Textual structure and names Test

A shader file must begin with the directive `"use typeshade"` as its first statement.

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

## Rationale

the directive is what tells the compiler and the language service that the file is a shader and not host code; the bundler and a host program’s `tsconfig` read the file’s name first, which [Rule 3.8](https://typeshade.dev/reference/rules/3-8/) fixes as `*.shade.ts`, and the directive is what they check it against.

## Derives from

surface §1 and `src/compiler/ts/source-file.ts`.

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

`TS8001 MISSING_DIRECTIVE`, which yields an otherwise empty result, for a file with no directive at all; `TS8069 MISPLACED_DIRECTIVE` on a directive after another top-level statement, another string directive included, with the rest of the file still checked ([#200](https://github.com/typeshade/typeshade/issues/200), proposal 0012), pinned by `src/compiler/ts/directive-placement.test.ts`.

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

- [`src/compiler/ts/compile.contract.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compile.contract.test.ts#L1)
- [`src/compiler/ts/directive-placement.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/directive-placement.test.ts#L1)

## Explained in

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

- [§1 Resources — `declare`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#1-resources--declare)
- [§68 Importing another shader module](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#68-importing-another-shader-module)

## Error codes that enforce it

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

**[`TS8001`](https://typeshade.dev/reference/errors/ts8001/) `MISSING_DIRECTIVE`**

A file compiled as TypeShade that has no `"use typeshade"` directive at all.

**[`TS8069`](https://typeshade.dev/reference/errors/ts8069/) `MISPLACED_DIRECTIVE`**

A `"use typeshade"` directive after another top-level statement (Rule 3.1). In ECMAScript a directive is only a leading string statement, so TypeScript reads a late one as an ordinary string. The fix is to move the directive, not to add one; a file with no directive at all is `MISSING_DIRECTIVE`.

## See also

- [Rule 2.4](https://typeshade.dev/reference/rules/2-4/) Test
- [Rule 3.2](https://typeshade.dev/reference/rules/3-2/) Test
- [Rule 3.8](https://typeshade.dev/reference/rules/3-8/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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