Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] object properties or class fields, methods are also converted to snake_case #116

Closed
yutak23 opened this issue Jun 25, 2023 · 0 comments · Fixed by #117
Closed

Comments

@yutak23
Copy link
Contributor

yutak23 commented Jun 25, 2023

I use this library in TypeScript (thank you for developing it).

I have recently submitted an issue, but I have found another issue, so I would like to report it again.

When the following implementation, the type definitions of Date and class fields and methods are also converted to snake_case.

class Point {
	x: number;
	y: number;
	addPoint(point: Point): Point {
		return ...;
	}
	constructor(x: number, y: number) {
		...
	}
}

interface Person {
	firstName: string;
	lastName: string;
	age: number;
}

const point = new Point(0, 10);
const person: Person = {
	firstName: 'Yuta',
	lastName: 'Katayama',
	age: 30
};

const result1 = snakecaseKeys({ foo: person, nested: { fooBaz: point } });
const result2 = snakecaseKeys({ fooBaz: "fooBaz", foo_bar: new Date() });
// type structure of `result1`
const result1: {
    foo: {
        first_name: string;
        last_name: string;
        age: number;
    };
    nested: {
        foo_baz: {
            x: number;
            y: number;
            add_point: {};
        };
    };
}

// type structure of `result2`
const result2: {
    foo_baz: string;
    foo_bar: {
        to_string: {};
        to_date_string: {};
        to_time_string: {};
        to_locale_string: {};
        to_locale_date_string: {};
        to_locale_time_string: {};
        value_of: {};
        get_time: {};
        get_full_year: {};
        ... 34 more ...;
        [Symbol.toPrimitive]: {};
    };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant