Flatten Tree Leaves Typescript (reversed)

I need help dealing with generics.
The function should “pick” leaves and in case of duplicates raise the branch.

const inputSchema = {
    playerResponse: {
        videoDetails: {
            title: 'pick',
            shortDescription: 'pick',
            thumbnail: {
                thumbnails: {
                    '4': {
                        url: 'pick',
                        height: 'pick',
                        width: 'pick',
                    },
                },
            },
        },
    },
    streamingData: {
        formats: {
            0: {
                url: 'pick'
            }
        }
    }
}
type output = {
    videoDetails: {
        title: string,
        shortDescription: string,
    },
    thumbnails: [
        null,
        null,
        null,
        null,
        {
            url: string,
            height: number,
            width: number,
        },
    ],
    formats: [
        {
            url: string,
        },
    ],
}

function flattenSchema<T>(input:T){
    return ...
}

I’ve tried using dot-prop to flatten the structure, but I’m having trouble with the types. Specifically, I’m not sure how to maintain the correct type information after flattening the structure.

for (const path of flattenedPaths) {
    try {
        let value = getProperty(schema, path)
        if (!value) {
            value = undefined // erase unknown values
        }

        const apiValue = getProperty(sourceOfTruth, path)

        const lastPath = path.split('.')?.splice(-2)?.join('.') || ''

        // modify by reference
        setProperty(outputSchema, lastPath, apiValue)
    } catch (error) {}
}
return Ok({ body: outputSchema })

I would appreciate any advice or guidance on how to properly flatten this data structure with generics in TypeScript. Thank you in advance for your help!