---
title: "규칙 4.1: 타입, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 4.1(타입)입니다. Every type an author writes must be a type borrowed from WGSL under a TypeScript spelling…"
url: https://typeshade.dev/ko/reference/rules/4-1/
language: ko
---

# 규칙 4.1

4장, 타입 테스트

Every type an author writes must be a type borrowed from WGSL under a TypeScript spelling, a member of the `f64` family ([Rule 4.4](https://typeshade.dev/ko/reference/rules/4-4/)), a key type, or a type ECMAScript defines that the compiler represents ([Rule 1.5](https://typeshade.dev/ko/reference/rules/1-5/)). A union of string literal types, or one string literal type, is a key type (change 0081): a `u32` under that spelling, whose members are its values, each held as its id, the member’s index in the order of the members’ UTF-16 code units. A key type takes `===`, `!==` and `switch` over its members, and no other operator; a value of another key type, or a number, is no value of it. `Record<K, V>` with `K` a key type is an `array<V, N>`, `N` the number of members, indexed by the member’s id (change 0081): `r[k]` with `k` of the key type, `r.g` and `r["g"]` the constant index of `"g"`, and an object literal with one value for each member, in any order, its value.

`Record<K, V>` also takes an enum or a union of integer literals when its distinct values are exactly 0 through N-1, indexed by the member value; other numeric domains are refused with their actual values (change 0081, decision 2).

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

## 근거

the layout, the constructors, and the builtins of a type borrowed from WGSL are WGSL’s, and a type WGSL does not have has none of those; a type ECMAScript defines keeps ECMAScript’s meaning and takes the representation the compiler chooses ([Rule 1.5](https://typeshade.dev/ko/reference/rules/1-5/)), as `Map` and `Set` do (change 0080).

## 출처

`changes/0100-typescript-meaning.md` (section 2); [Types](https://gpuweb.github.io/gpuweb/wgsl/#types), [Plain Types](https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section) and [Texture and Sampler Types](https://gpuweb.github.io/gpuweb/wgsl/#texture-sampler-types).

## 검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

`SUPPORTED_TYPE_NAMES` in `src/compiler/ts/type-map.ts` (`TS8002 UNKNOWN_TYPE` names the whole list) and `surface-names.test.ts` for the spellings; `keyTypeT` in `src/compiler/ts/key-types.ts` and `src/compiler/ts/key-types.test.ts` for the key types, in the compiler and in the language service.

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

- [`src/compiler/ts/key-types.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/key-types.test.ts#L1)
- [`src/compiler/ts/key-types.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/key-types.ts#L1)
- [`src/compiler/ts/type-map.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-map.ts#L1)
- [`src/core/spec-conformance/surface-names.test.ts:52`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/spec-conformance/surface-names.test.ts#L52)

## 설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

- [§75 String keys and Record](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#75-string-keys-and-record)

## 적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

**[`TS8002`](https://typeshade.dev/ko/reference/errors/ts8002/) `UNKNOWN_TYPE`**

아무것도 선언하지 않은 타입 이름입니다. 매개변수, 타입 인자, 별칭, `implements` 절, 기반 클래스 어디에 써도 걸리고, 이 표면이 매퍼가 읽는 자리에서 받지 않는 타입도 여기에 속합니다([규칙 2.1](https://typeshade.dev/ko/reference/rules/2-1/)). 파일이 선언했지만 구조체로 모으지 않은 기반은 `STRUCT_FIELD`입니다.

## 함께 보기

- [규칙 3.9](https://typeshade.dev/ko/reference/rules/3-9/) 테스트
- [규칙 4.2](https://typeshade.dev/ko/reference/rules/4-2/) 테스트
- [규칙 1.5](https://typeshade.dev/ko/reference/rules/1-5/)
- [규칙 4.4](https://typeshade.dev/ko/reference/rules/4-4/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

- [`docs/language-design.md:331`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L331) (설계 문서)
- [`reqs/rules/RULE-0401.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0401.md) (추적 항목)
