KeyOf
타입, 타입 분류
Turns a ShaderType literal into the precise string key that Node carries as its compile-time phantom: KeyOf<typeof vec3fT> resolves to 'vec3<f32>', so a vec2 and vec3 operand mismatch fails tsc before the runtime SD0002 check in typeKey and typeEq would catch it.
import type { KeyOf } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
type KeyOf<T> = T extends { kind: 'scalar'; scalar: infer S extends string } ? S : T extends { kind: 'f64' } ? 'f64' : T extends { kind: 'vec64'; n: infer N extends number } ? `vec${N}<f64>` : T extends { kind: 'vec'; n: infer N extends number; elem: infer E extends string } ? `vec${N}<${E}>` : T extends { kind: 'mat'; cols: infer C extends number; rows: infer R extends number; elem: infer E extends string; } ? `mat${C}x${R}<${E}>` : T extends { kind: 'struct'; name: infer N extends string } ? `struct:${N}` : T extends { kind: 'array'; elem: infer E; size: infer S } ? S extends number ? `array<${KeyOf<E>},${S}>` : `array<${KeyOf<E>}>` : T extends { kind: 'atomic'; elem: infer E extends string } ? `atomic<${E}>` : T extends { kind: 'void' } ? 'void' : T extends { kind: 'texture'; dim: '2d-ms'; elem: infer E extends string } ? `texture_multisampled_2d<${E}>` : T extends { kind: 'texture'; dim: '2d-array'; elem: infer E extends string } ? `texture_2d_array<${E}>` : T extends { kind: 'texture'; dim: '2d'; elem: infer E extends string } ? `texture_2d<${E}>` : T extends { kind: 'texture'; dim: 'cube'; elem: infer E extends string } ? `texture_cube<${E}>` : T extends { kind: 'texture'; dim: '3d'; elem: infer E extends string } ? `texture_3d<${E}>` : T extends { kind: 'texture'; dim: '1d'; elem: infer E extends string } ? `texture_1d<${E}>` : T extends { kind: 'texture'; dim: 'cube-array'; elem: infer E extends string; } ? `texture_cube_array<${E}>` : T extends { kind: 'sampler' } ? 'sampler' : string;설명
Turns a ShaderType literal into the precise string key that Node carries as its
compile-time phantom: KeyOf<typeof vec3fT> resolves to 'vec3<f32>', so a vec2 and
vec3 operand mismatch fails tsc before the runtime SD0002 check in typeKey and
typeEq would catch it. It narrows only against a T that kept its literal shape
(the as const satisfies ShaderType constants in this module, or a structT or
arrayT result); a widened ShaderType collapses to the string fallback. Every arm
mirrors one case of typeKey, and a new ShaderType variant needs an arm in both.
함께 보기
소스
src/core/ir/types.ts, 832행, 커밋 c66579bf 기준