feat(blog): as const와 keyof typeof로 enum 없이 안전한 상수 만들기 (#38)#128
Merged
Conversation
- enum이 남기는 런타임 코드·역방향 매핑과 nominal 특성의 함정을 정리 - as const + (typeof X)[keyof typeof X]로 값·타입 유니온 만드는 패턴 설명 - 모든 코드 예제를 tsc 5.5로 검증(에러/컴파일 출력 실측)
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
이슈 #38 을 블로그 포스트로 작성했습니다.
frontend시리즈에 추가됩니다.apps/blog/src/app/(main)/posts/frontend/ts-as-const/page.mdx/posts/frontend/ts-as-const다루는 내용
enum이 타입이 아니라 값이라 컴파일 후 런타임 코드(IIFE + 숫자 enum 역방향 매핑)를 남기는 점enum의 nominal 특성 — 값이 같은 평범한 문자열도 거부const enum의 한계 — ambient const enum은isolatedModules에서 TS2748로 막힘as const+(typeof X)[keyof typeof X]로 값과 리터럴 유니온 타입을 함께 만드는 실전 패턴satisfies로 형태 검증과 리터럴 유지를 동시에검증
tsc 5.5.4로 실측 검증 (에러 메시지·Object.keys이중화·컴파일 출력)pnpm --filter blog run build성공 —/posts/frontend/ts-as-const정적 생성 확인관례 준수
##로 시작, frontmatter는@libs/frontmatter사용postId(ts-as-const)와 폴더명 일치Closes #38