Type Challenges Judge

ValidDate

提出詳細

type MaxDay = { "01": 31, "02": 28, "03": 31, "04": 30, "05": 31, "06": 30, "07": 31, "08": 31, "09": 30, "10": 31, "11": 30, "12": 31, } type TNumOf<N extends number, _A extends 0[] = []> = _A["length"] extends N ? _A : TNumOf<N, [..._A, 0]>; type Gte<Left extends number, Right extends number> = TNumOf<Left> extends [...TNumOf<Right>, ...infer Rest] ? true : false; type Lte<Left extends number, Right extends number> = TNumOf<Right> extends [...TNumOf<Left>, ...infer _] ? true : false; type ValidDate_Impl<Month extends string, Day extends string> = Month extends keyof MaxDay ? Day extends `${infer DayN extends number}` ? DayN extends 0 ? false : Gte<DayN, 0> extends true ? Lte<DayN, MaxDay[Month]> extends true ? true : false : false : false : false; type ValidDate<T extends string> = T extends `${infer M1 extends number}${infer M2 extends number}${infer D1 extends number}${infer D2 extends number}${infer R}` ? R extends "" ? ValidDate_Impl<`${M1}${M2}`, `${D1 extends 0 ? "" : D1}${D2}`> : false : false;
提出日時2025-01-20 10:37:58
問題ValidDate
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<ValidDate<'0102'>, true>>, Expect<Equal<ValidDate<'0131'>, true>>, Expect<Equal<ValidDate<'1231'>, true>>, Expect<Equal<ValidDate<'0229'>, false>>, Expect<Equal<ValidDate<'0100'>, false>>, Expect<Equal<ValidDate<'0132'>, false>>, Expect<Equal<ValidDate<'1301'>, false>>, ]