ValidBracket
type LengthOfString<S extends Readonly<string>, L extends string[] = []> = S extends '' ? L['length'] : S extends `${infer First}${infer Last}` ? LengthOfString<Last, [First,...L]> : never;
type ReverseString<T extends string> = T extends `${infer First}${infer Rest}` ? `${ReverseString<Rest>}${First}` : T;
type CurFirst<T extends string> = T extends `${infer First}${infer Rest}` ? Rest : '';
type CurLast<T extends string> = ReverseString<CurFirst<ReverseString<T>>>;
type FirstChar<T extends string> = T extends `${infer First}${infer Rest}` ? First : T;
type LastChar<T extends string> = FirstChar<ReverseString<T>>;
type ValidBracketImplement<T extends string, U extends string = ''> =
LengthOfString<T> extends 0
? LengthOfString<U> extends 0
? true
: false
: FirstChar<T> extends ')'
? LastChar<U> extends '('
? ValidBracketImplement<CurFirst<T>,CurLast<U>>
: false
:ValidBracketImplement<CurFirst<T>, `${FirstChar<T>}${U}`>;
프로그래머스 문제 중 "올바른 괄호" 문제를 타입스크립트 만으로 풀어본 문제입니다.