Type Challenges Judge

MinusOne

提出詳細

type TupleOfLengthInner<N extends string, Tuple extends any[] = []> = `${Tuple['length']}` extends N ? Tuple : TupleOfLengthInner<N, [...Tuple, 0]> type TupleOfLength<N extends string, T extends any[] = []> = N extends `${infer First}${infer Rest}` ? TupleOfLength<Rest, [...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...TupleOfLengthInner<First>]> : T; type MinusOne<T extends number> = TupleOfLength<`${T}`> extends [infer _, ...infer Rest] ? Rest['length'] : never;
提出日時2023-08-12 13:09:50
問題MinusOne
ユーザーtekihei2317
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<MinusOne<1>, 0>>, Expect<Equal<MinusOne<55>, 54>>, Expect<Equal<MinusOne<3>, 2>>, Expect<Equal<MinusOne<100>, 99>>, Expect<Equal<MinusOne<1101>, 1100>>, ]