---
title: "TS8003 TYPE_MISMATCH: TypeShade 컴파일러가 진단에 붙이는 오류 코드 한 가지"
description: "TS8003 TYPE_MISMATCH, TypeShade 컴파일러의 오류 코드입니다. 연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(T | undefined, T | null…"
url: https://typeshade.dev/ko/reference/errors/ts8003/
language: ko
---

# `TS8003`

프런트엔드 코드 `TYPE_MISMATCH`

연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(`T | undefined`, `T | null`, `T | null | undefined`)을 읽거나([규칙 7.10](https://typeshade.dev/ko/reference/rules/7-10/)), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는 `f32` 값, `Math.pow(-2., 2.)`처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.

레지스트리에는 이 상수에 대한 문서 주석이 없습니다. 그래서 위 설명은 컴파일러가 이 코드와 함께 내는 메시지를 보고 이 사이트가 쓴 것입니다.

레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

## 예제

example.shade.ts

```ts
"use typeshade"
function gain(value: f32 | null | undefined): f32 {
  return value * 2.
}
@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, gain(null), 1.)
}
```

빌드할 때 고정된 컴파일러로 이 프로그램을 컴파일하면 다음 진단이 나옵니다.

**TS8003** error, 3행: "value" is "`f32` | null | undefined" here, and "\*" takes an `f32`. Test it first, "if (value != null)", or give the absent case a value, "value ?? 0.".

## 고치는 법

같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.

example.shade.ts

```ts
"use typeshade"
function gain(value: f32 | null | undefined): f32 {
  if (value == null) { return 0. }
  return value * 2.
}
@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, gain(null), 1.)
}
```

## 이 코드가 적용하는 규칙

**[규칙 2.3](https://typeshade.dev/ko/reference/rules/2-3/) 테스트**

A value sometimes has to cross between a representation the compiler chose and one the target has: an `f64` and the two `f32` halves that carry it across an interface of `f32`.

**[규칙 4.8](https://typeshade.dev/ko/reference/rules/4-8/) 테스트**

Every `matCxR` with `C` and `R` in 2, 3, 4 must be a type, and a square one must also answer to `matN`.

**[규칙 5.3](https://typeshade.dev/ko/reference/rules/5-3/) 테스트**

There is no implicit conversion between concrete types; an `i32` beside a `u32`, or an integer beside a float, must be refused with the cast to write.

**[규칙 5.4](https://typeshade.dev/ko/reference/rules/5-4/) 테스트**

A literal must fit the type it takes; `-1` in a `u32` position and `2147483648` in an `i32` position are refused as written.

**[규칙 6.3](https://typeshade.dev/ko/reference/rules/6-3/) 테스트**

A top-level `const` is a module constant: a scalar must fold to one value carried at double precision for the oracle and at the target’s precision for emit, and a vector, array, or struct must carry a constant-foldable expression every backend evaluates.

**[규칙 6.6](https://typeshade.dev/ko/reference/rules/6-6/) 테스트**

An entry point’s inputs and outputs are explicit parameters and return values.

**[규칙 7.1](https://typeshade.dev/ko/reference/rules/7-1/) 테스트**

An operator, a swizzle, an index, and a call must mean what WGSL’s typing table gives them.

**[규칙 7.4](https://typeshade.dev/ko/reference/rules/7-4/) 테스트**

A shift amount the compiler can fold must be in 0 to 31; a divisor the compiler can prove to be zero must be refused where the division is lowered.

**[규칙 7.5](https://typeshade.dev/ko/reference/rules/7-5/) 테스트**

A `for` loop means what it means in TypeScript: its initializer runs once, its condition (`true` when it has none) is tested before each trip, and its update runs after each trip and at each `continue` (change 0136).

**[규칙 7.10](https://typeshade.dev/ko/reference/rules/7-10/) 테스트**

`T | undefined` and `T | null` are optional values.

**[규칙 8.18](https://typeshade.dev/ko/reference/rules/8-18/) 테스트**

A function whose parameter has a function type, written out (`f: (x: f32) => f32`) or through a type alias of one, takes a function: a function declared at the top of the file or of a namespace, a method, a static method, a constructor, a field that holds a function ([Rule 8.16](https://typeshade.dev/ko/reference/rules/8-16/)) and a local function ([Rule 8.17](https://typeshade.dev/ko/reference/rules/8-17/)).

**[규칙 8.19](https://typeshade.dev/ko/reference/rules/8-19/) 테스트**

A function that writes no return type returns what its body does, as TypeScript infers it: a function of the file or of a namespace, a local function ([Rule 8.17](https://typeshade.dev/ko/reference/rules/8-17/)), each instance of a generic function ([Rule 8.9](https://typeshade.dev/ko/reference/rules/8-9/)) and of a function that takes a function ([Rule 8.18](https://typeshade.dev/ko/reference/rules/8-18/)), a method, a getter and a field that holds a function ([Rule 8.16](https://typeshade.dev/ko/reference/rules/8-16/)) take the type of their first `return` with a value, the `return`s after it are typed against that type as against a written one, and one with no such `return` returns nothing.

**[규칙 12.6](https://typeshade.dev/ko/reference/rules/12-6/) 테스트**

A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.

## 함께 보기

**[`SD0001`](https://typeshade.dev/ko/reference/errors/sd0001/)**

matrix × vector size mismatch

**[`SD0002`](https://typeshade.dev/ko/reference/errors/sd0002/)**

binary op on mismatched vectors

**[`SD0003`](https://typeshade.dev/ko/reference/errors/sd0003/)**

arithmetic op on a bool operand

**[`SD0004`](https://typeshade.dev/ko/reference/errors/sd0004/)**

binary op on incompatible types

**[`SD0009`](https://typeshade.dev/ko/reference/errors/sd0009/)**

.select() on a non-bool condition

**[`SD0010`](https://typeshade.dev/ko/reference/errors/sd0010/)**

select branches have differing types

**[`SD0017`](https://typeshade.dev/ko/reference/errors/sd0017/)**

literal cannot be spelled by the target

**[`SD0041`](https://typeshade.dev/ko/reference/errors/sd0041/)**

unsupported operation on `f64` operands

- [타입](https://typeshade.dev/ko/guide/language/types/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.

- [`src/compiler/ts/abstract-const.ts:713`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/abstract-const.ts#L713) (8곳)
- [`src/compiler/ts/builtin-check.ts:341`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtin-check.ts#L341) (4곳)
- [`src/compiler/ts/builtin-type-form.ts:98`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtin-type-form.ts#L98)
- [`src/compiler/ts/internal-ops.ts:73`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/internal-ops.ts#L73)
- [`src/compiler/ts/lit-coerce.ts:713`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lit-coerce.ts#L713)
- [`src/compiler/ts/lower/array-constructor/from.ts:181`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-constructor/from.ts#L181)
- [`src/compiler/ts/lower/array-constructor/lower.ts:111`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-constructor/lower.ts#L111)
- [`src/compiler/ts/lower/array-constructor/lowering.ts:42`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-constructor/lowering.ts#L42)
- [`src/compiler/ts/lower/array-methods.ts:66`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-methods.ts#L66) (3곳)
- [`src/compiler/ts/lower/array-methods/named-function.ts:31`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-methods/named-function.ts#L31) (4곳)
- [`src/compiler/ts/lower/array-methods/value-methods.ts:37`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/array-methods/value-methods.ts#L37) (2곳)
- [`src/compiler/ts/lower/atomics.ts:71`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/atomics.ts#L71) (5곳)
- [`src/compiler/ts/lower/barriers.ts:82`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/barriers.ts#L82)
- [`src/compiler/ts/lower/class-methods/construct.ts:125`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/class-methods/construct.ts#L125)
- [`src/compiler/ts/lower/collections.ts:95`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/collections.ts#L95) (2곳)
- [`src/compiler/ts/lower/const-call.ts:47`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/const-call.ts#L47) (2곳)
- [`src/compiler/ts/lower/control.ts:166`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control.ts#L166) (2곳)
- [`src/compiler/ts/lower/control/for-header.ts:225`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/for-header.ts#L225)
- [`src/compiler/ts/lower/control/for-of.ts:61`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/for-of.ts#L61)
- [`src/compiler/ts/lower/control/switch.ts:32`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/switch.ts#L32)
- [`src/compiler/ts/lower/control/while.ts:22`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/while.ts#L22) (2곳)
- [`src/compiler/ts/lower/expression-array.ts:121`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-array.ts#L121) (3곳)
- [`src/compiler/ts/lower/expression-array/element.ts:37`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-array/element.ts#L37)
- [`src/compiler/ts/lower/expression-array/fold.ts:98`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-array/fold.ts#L98) (3곳)
- [`src/compiler/ts/lower/expression-array/list-uses.ts:20`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-array/list-uses.ts#L20)
- [`src/compiler/ts/lower/expression-call.ts:154`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call.ts#L154) (8곳)
- [`src/compiler/ts/lower/expression-call/args.ts:135`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/args.ts#L135)
- [`src/compiler/ts/lower/expression-call/bit-builtins.ts:70`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/bit-builtins.ts#L70) (5곳)
- [`src/compiler/ts/lower/expression-call/gather.ts:30`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/gather.ts#L30) (6곳)
- [`src/compiler/ts/lower/expression-call/matrix-ctor.ts:70`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/matrix-ctor.ts#L70) (3곳)
- [`src/compiler/ts/lower/expression-call/multisampled.ts:59`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/multisampled.ts#L59) (2곳)
- [`src/compiler/ts/lower/expression-call/select-and-reduce.ts:111`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/select-and-reduce.ts#L111) (5곳)
- [`src/compiler/ts/lower/expression-call/storage-depth.ts:48`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/storage-depth.ts#L48) (8곳)
- [`src/compiler/ts/lower/expression-call/texture-call.ts:39`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call/texture-call.ts#L39) (7곳)
- [`src/compiler/ts/lower/expression-misc.ts:168`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-misc.ts#L168)
- [`src/compiler/ts/lower/expression-misc/scalar-calls.ts:93`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-misc/scalar-calls.ts#L93) (3곳)
- [`src/compiler/ts/lower/expression-prop/object-literal.ts:166`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-prop/object-literal.ts#L166) (4곳)
- [`src/compiler/ts/lower/expression.ts:150`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression.ts#L150) (27곳)
- [`src/compiler/ts/lower/expression/key-operands.ts:32`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression/key-operands.ts#L32) (3곳)
- [`src/compiler/ts/lower/expression/kindless-division.ts:58`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression/kindless-division.ts#L58) (4곳)
- [`src/compiler/ts/lower/expression/operand-reads.ts:108`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression/operand-reads.ts#L108)
- [`src/compiler/ts/lower/for-step-fit.ts:44`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/for-step-fit.ts#L44) (2곳)
- [`src/compiler/ts/lower/function-args.ts:129`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function-args.ts#L129) (5곳)
- [`src/compiler/ts/lower/function.ts:2175`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L2175) (3곳)
- [`src/compiler/ts/lower/index-select.ts:74`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/index-select.ts#L74) (9곳)
- [`src/compiler/ts/lower/made-array/lower.ts:230`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/made-array/lower.ts#L230)
- [`src/compiler/ts/lower/operator-kinds.ts:163`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/operator-kinds.ts#L163) (3곳)
- [`src/compiler/ts/lower/optional-values/diagnostic.ts:11`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/optional-values/diagnostic.ts#L11)
- [`src/compiler/ts/lower/statement/assign.ts:141`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/assign.ts#L141) (3곳)
- [`src/compiler/ts/lower/statement/binding-pattern.ts:74`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/binding-pattern.ts#L74)
- [`src/compiler/ts/lower/statement/bitwise-assign.ts:102`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/bitwise-assign.ts#L102) (5곳)
- [`src/compiler/ts/lower/statement/branch.ts:33`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/branch.ts#L33) (2곳)
- [`src/compiler/ts/lower/statement/compound-assign.ts:122`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/compound-assign.ts#L122) (5곳)
- [`src/compiler/ts/lower/statement/declaration-kind.ts:109`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/declaration-kind.ts#L109) (4곳)
- [`src/compiler/ts/lower/subgroups.ts:82`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/subgroups.ts#L82) (2곳)
- [`src/compiler/ts/module-const.ts:145`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-const.ts#L145) (14곳)
- [`src/compiler/ts/module-vars/inferred-value.ts:16`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-vars/inferred-value.ts#L16)
- [`src/compiler/ts/remedies/validate.ts:75`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/remedies/validate.ts#L75) (2곳)
- [`src/compiler/ts/structs/field-shapes.ts:83`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/structs/field-shapes.ts#L83)
- [`src/language-service/check.ts:226`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/check.ts#L226)
- [`src/language-service/diagnostics.ts:78`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics.ts#L78) (2곳)
- [`src/language-service/diagnostics/refused-attributes.ts:142`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics/refused-attributes.ts#L142)
- [`src/language-service/diagnostics/refused-list.ts:28`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics/refused-list.ts#L28)
- [`src/language-service/service.ts:199`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/service.ts#L199)
