matchEnum
이 페이지에서

matchEnum()

함수, 작성 분류

Exhaustive integer dispatch over an enumU32: matchEnum(kind, Kind, { Line: () => …, Fill: () => …, … }).

import { matchEnum } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function matchEnum<M extends Record<string, number>, R extends string>(
scrutinee: ReadonlyNode<ScalarKey>,
e: EnumU32<M>,
arms: { readonly [K in keyof M]: () => ReadonlyNode<R> },
): Node<R>

매개변수

scrutinee ReadonlyNode<ScalarKey>
e EnumU32<M>
arms { readonly [K in keyof M]: () => ReadonlyNode<R> }

반환값

Node<R>

설명

Every member must have an arm; omit one and tsc errors, since the arms type is a mapped type over the enum’s keys, so adding a member surfaces every dispatch site that does not handle it. It builds the same matchExpr the hand-written form would: the last-declared member becomes the switch default, so the emitted code is a standard exhaustive switch. Arms are zero-argument functions, called in declaration order.

관련 가이드

함께 보기

소스

src/core/ir/node.ts, 2360행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고