문제
https://github.com/type-challenges/type-challenges/blob/main/questions/00003-medium-omit/README.md
type-challenges/questions/00003-medium-omit/README.md at main · type-challenges/type-challenges
Collection of TypeScript type challenges with online judge - type-challenges/type-challenges
github.com
✅ 내 풀이
type MyOmit<T, K extends keyof T> = {
[P in keyof T as P extends K ? never : P]: T[P];
};
K는 T의 하위니깐 타입 좁히고,
Exclude를 써서 K 이외의 값에 대해 루프를 돌아야 되는데 Exclude를 사용하면 약간 반칙 같으니
타입 단언해서 never 로 K 에 있는 값들은 없애주기
'TypeScript' 카테고리의 다른 글
| 📢 Zod로 유효성 검증과 타입 선언하기 (0) | 2025.05.28 |
|---|---|
| 친해지기3-Type Challenges : 00011-easy-tuple-to-object (0) | 2025.04.30 |
| 친해지기2-Type Challenges : 00007-easy-readonly (1) | 2025.04.29 |
| 친해지기1- Type Challenges : 00004-easy-pick (0) | 2025.04.28 |
| [TS] 타입 가드 & 타입 내로잉(is, as const, keyof, typeof, as) (0) | 2025.04.23 |