I have a function that takes a camelCase object and returns the same object in snake_case format.
// Let's consider these types
interface CamelData {
exempleId: number
myData:string
}
interface SnakeData {
exemple_id: number
my_data: string
}
export const camelToSnake = (
camelData: Partial<CamelData>
): Partial<SnakeData> => {
return {
exemple_id: camelData.exempleId,
my_data: camelData.myData
}
My goal is to make sure that the return type of the function is SnakeData when the input type is CamelData.
I'm looking for a solution that works like this:
export const camelToSnake = (
camelData: Partial<CamelData>
): if (camelData is of type CamelData) {SnakeData} else {Partial<SnakeData>} => {
return {
exemple_id: camelData.exempleId,
my_data: camelData.myData
}
Any suggestions or help would be greatly appreciated. Have a wonderful day!