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] If the deep: true option is set, even the object's properties will be converted. #111

Closed
yutak23 opened this issue Jun 26, 2023 · 0 comments · Fixed by #112
Closed

Comments

@yutak23
Copy link
Contributor

yutak23 commented Jun 26, 2023

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

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

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

const point = new Point(0, 10);

const result = camelcaseKeys({ foo_Baz: point, foo_bar: new Date() }, { deep: true });
// type structure of `result`
const result: {
    fooBaz: {
        x: number;
        y: number;
        addPoint: (point: Point) => Point;
    };
    fooBar: {
        toString: () => string;
        toDateString: () => string;
        toTimeString: () => string;
        toLocaleString: {
            (): string;
            (locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): string;
            (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
        };
        ... 39 more ...;
        [Symbol.toPrimitive]: {
            ...;
        };
    };
}

I think the expected value is below.

const result: {
    fooBaz: Point;
    fooBar: Date
}
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