kbrabrand / camelize-ts

A typescript typed camelCase function that recursively camel cases a snake cased object structure
22 stars 6 forks source link

Wrong remapping of nested arrays #57

Open Goldziher opened 2 weeks ago

Goldziher commented 2 weeks ago

Hi there,

Given the following type:

interface ChatRequestBody {
    drive_id: string;
    user_query: string;
    session_id: string;
    folders: ('PRE' | 'VDR' | 'AUDIT' | 'POST')[];
}

The folders value gets remapped wrongly when applied with Camelize.

expected type CamelizeChatRequestBody = Camelize<ChatRequestBody> to be equal to this:

type CamelizeChatRequestBody = {
    driveId: string;
    userQuery: string;
    sessionId: string;
    folders: ('PRE' | 'VDR' | 'AUDIT' | 'POST')[];
}

But its actually equal to this:

type CamelizeChatRequestBody = {
    driveId: string;
    userQuery: string;
    sessionId: string;
    folders: 'PRE'[] | 'VDR'[] | 'AUDIT'[] | 'POST'[];
}

I therefore need to do something like this:

type CamelizeChatRequestBody = Camelize<Omit<ChatRequestBody, "folders>> & { folders: ('PRE' | 'VDR' | 'AUDIT' | 'POST')[] }