---
title: "규칙 6.9: 선언과 리소스, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 6.9(선언과 리소스)입니다. A struct must be the members written in it, in one of four spellings (class, interface…"
url: https://typeshade.dev/ko/reference/rules/6-9/
language: ko
---

# 규칙 6.9

6장, 선언과 리소스 테스트

A struct must be the members written in it, in one of four spellings (`class`, `interface`, a `type` over an object literal, an object type literal written where a type stands). On a class or an interface with an `extends` clause it must be the base’s members first and its own after, through a chain of any depth. A class’s members include the fields its constructor’s parameter properties declare, and a field written without a type takes the one its initializer names ([Rule 8.14](https://typeshade.dev/ko/reference/rules/8-14/)). An interface that declares a method is a contract and not a struct: a class may name it in `implements` and a type parameter in its constraint (`<T extends Shape>`), and a value typed by it must be refused with the remedy, once, where the interface declares the method. A call signature, an index signature, and an optional member must be refused.

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

## 근거

a WGSL structure has no form for any of the three, and dropping one silently would change the buffer layout the host fills; a base’s members are laid out where TypeScript’s structural typing says they are, so an `extends` drops nothing. An interface with a method says what a class supplies, and a call through it runs the body of the class the value is, which static dispatch finds through that class or through the type parameter a call binds ([Rule 8.9](https://typeshade.dev/ko/reference/rules/8-9/)); a value of the interface’s own type would have to pick the body at run time, which a WGSL function cannot.

## 출처

[Structure Types](https://gpuweb.github.io/gpuweb/wgsl/#struct-types); TypeScript’s [`implements` clauses](https://www.typescriptlang.org/docs/handbook/2/classes.html#implements-clauses) and [generic constraints](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints); surface §2; surface §26 (“`extends`, `abstract` and `implements`”, roadmap 0.3 item T5, [#92](https://github.com/typeshade/typeshade/issues/92); “An interface with methods is a contract”).

## 검증 방식

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

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

`TS8010 STRUCT_FIELD`, pinned by `src/compiler/ts/type-structs.test.ts` (a method signature on an interface a value is typed by, `"Bad" declares a method, so it is a contract a class implements and not a value a shader holds: take the class that implements it, or a type parameter it constrains, "<T extends Bad>(v: T)".`; a call signature, an index signature, an optional field); `src/compiler/ts/class-syntax.test.ts` for a contract in `implements` and in a constraint, held to one value on every CPU path, and `examples/gallery/class-parts/class-parts.shade.ts` in the compile gate; `src/compiler/ts/inheritance.test.ts` (`a derived struct is its base plus its own`) for the layout.

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

- [`examples/shade-examples.test.ts:26`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/shade-examples.test.ts#L26)
- [`src/compiler/ts/class-syntax.test.ts:1755`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-syntax.test.ts#L1755)
- [`src/compiler/ts/inheritance-methods.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance-methods.test.ts#L1)
- [`src/compiler/ts/inheritance-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance-refusals.test.ts#L1)
- [`src/compiler/ts/inheritance.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/inheritance.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)

## 설명하는 절

커밋 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)
- [§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)

## 적용하는 오류 코드

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

**[`TS8010`](https://typeshade.dev/ko/reference/errors/ts8010/) `STRUCT_FIELD`**

구조체 필드나 선언의 모양이 잘못되었습니다. 필드가 없는 클래스는 받아들입니다. 이 코드는 잘못된 필드 선언, 클래스가 아닌 빈 구조체, 적용되지 않는 필드의 `@align`, 사용처마다 location이 둘로 갈리는 사용자 정의 값을 다룹니다([규칙 6.6](https://typeshade.dev/ko/reference/rules/6-6/)).

## 함께 보기

- [규칙 6.8](https://typeshade.dev/ko/reference/rules/6-8/) 테스트
- [규칙 6.10](https://typeshade.dev/ko/reference/rules/6-10/) 테스트
- [규칙 8.9](https://typeshade.dev/ko/reference/rules/8-9/)
- [규칙 8.14](https://typeshade.dev/ko/reference/rules/8-14/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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