Udemy/Ts/React-Extra-1: Zod #65
Open
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.
✍Udemy/Ts/React-Extra-1: Zod
🔗Reference
🔥KeyWord
📝Description
buttonPropsSchema
는 Zod의 object 메서드를 사용하여 props의 데이터 구조를 정의하고 있다. EnterColor와 LeaveColor가 모두 문자열(string) 타입이어야 함을 명시하며 props가 올바른 타입인지 유효성 검사를 수행하고 런타임에서 props를 검증하는 기준을 제공한다.z.infer<typeof buttonPropsSchema
>를 사용하여 buttonPropsSchema로부터 TypeScript 타입을 추출한다. Zod 스키마를 TypeScript 타입으로 변환하여 컴포넌트에 타입을 명시할 수 있도록 한다. props의 타입을 명확히 정의하여ButtonComponents
컴포넌트가 받는 props의 타입을 TypeScript가 type 추론을 할 수 있도록 도와준다.📌Summary