Skip to content

Fix CamelCaseKeys type#78

Merged
sindresorhus merged 3 commits intosindresorhus:mainfrom
nano72mkn:fix-camel_case_keys_deep_type
Oct 4, 2021
Merged

Fix CamelCaseKeys type#78
sindresorhus merged 3 commits intosindresorhus:mainfrom
nano72mkn:fix-camel_case_keys_deep_type

Conversation

@nano72mkn
Copy link
Copy Markdown
Contributor

The type of camelCaseKeys is incorrect and has been fixed.
When the type is object or undefined, the hierarchy after that remains in snakeCase.

interface ObjectOrUndefined {
	foo_bar: {
		foo_bar: {
			foo_bar: boolean;
		} | undefined;
	};
}

const objectOrUndefined: ObjectOrUndefined = {
	foo_bar: {
		foo_bar: {
			foo_bar: true
		}
	}
};

expectType<{ fooBar: { fooBar: { fooBar: boolean } | undefined } }>(
	camelcaseKeys(objectOrUndefined, {deep: true})
);

As a result of the test, the following error occurred.

Argument of type { fooBar: { fooBar: { foo_bar: boolean; } | undefined; }; } is not assignable to parameter of type { fooBar: { fooBar: { fooBar: boolean; } | undefined; }; }.
  The types of fooBar.fooBar are incompatible between these types.
    Type { foo_bar: boolean; } | undefined is not assignable to type { fooBar: boolean; } | undefined.
      Property fooBar is missing in type { foo_bar: boolean; } but required in type { fooBar: boolean; }. 

With this fix, the conversion will be correct as follows

{ fooBar: { fooBar: { fooBar: boolean } | undefined } }

@sindresorhus
Copy link
Copy Markdown
Owner

Tests are failing.

@sindresorhus
Copy link
Copy Markdown
Owner

@g-plane Would you be able to help review?

@g-plane
Copy link
Copy Markdown
Contributor

g-plane commented Sep 27, 2021

I think the failing tests aren't introduced in this PR, because the commits on main branch also break the tests.

@sindresorhus sindresorhus merged commit ece45c5 into sindresorhus:main Oct 4, 2021
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 this pull request may close these issues.

3 participants