목표

{
    colA: any;
    colB: any;
		...
}

주의사항

Type

type RemoveLineFeed<T extends string> = 
    T extends `\\n${infer A}` ? 
        A extends `${infer B}\\n` ? B
        : A
    : T extends `${infer A}\\n` ? A : T;
;

type Trim<T extends string, Acc extends string = '', Separator extends string = ' '> 
    = T extends `${infer Char}${infer Rest}`
        ? (Char extends Separator
            ? Trim<Rest, Acc>
            : Trim<Rest, `${Acc}${Char}`>)
        : (T extends ''
            ? Acc
            : never);

type TrimComments<T extends string> = 
      T extends `${infer Head}#${any}\\n${infer Tail}`
        ? TrimComments<`${Head}\\n${Tail}`> 
    : T extends `${infer Head}--${any}\\n${infer Tail}`
        ? TrimComments<`${Head}\\n${Tail}`>
    : T extends `${infer Head}/*${any}*/${infer Tail}`
        ? TrimComments<`${Head}${Tail}`>
    // : T extends `${infer Head}#${any}\\r\\n${infer Tail}`
    //     ? TrimComments<`${Head}\\r\\n${Tail}`>
    // : T extends `${infer Head}--${any}\\r\\n${infer Tail}`
    //     ? TrimComments<`${Head}\\r\\n${Tail}`>
    : T;

type ExtractSelectBody<T extends string> = 
    T extends `${string}SELECT${infer Body}FROM${string}` ? 
        Body : never;

type SplitComma<T extends string, TUnion = never> = 
    T extends `${infer Head},${infer Tail}` ? 
        SplitComma<Tail, TUnion | Head>
        : TUnion | T;

type PickAlias<T extends string> = 
    T extends `${any}AS ${infer Alias}` ? Alias : 
    T extends `${any}as ${infer Alias}` ? Alias : 
    T;

type SnakeToCamelCase<T extends string> =
    T extends `${infer Head}_${infer Tail}` ?
        `${Head}${Capitalize<SnakeToCamelCase<Tail>>}` : T;

export type ExtractOutputFromQuery<T extends string> = 
    T extends `${string}SELECT *${string}` ? Record<string, any> :
    T extends `${string}SELECT${string}` ? 
        (
            Record<
                SnakeToCamelCase<
                RemoveLineFeed<
                Trim<
                PickAlias<
                SplitComma<
                ExtractSelectBody<
                TrimComments<T>
                >
                >
                >
                >
                >
                >
            , any>
        )
        : any;

Examples

/*{
    name: any;
    pw: any;
    userId: any;
    yearsOld: any;
    userPhoneNumber: any;
}*/
type Example_ExtractOutput = ExtractOutputFromQuery<`
    SELECT user_id,
           user_name AS name,
           user_phone_number -- 코멘트1
          ,pass_word AS pw    # 코멘트2
          ,years_old         /* 코멘트3 */
      FROM table
     WHERE ANY_CONDITIONS
`>;