-
Notifications
You must be signed in to change notification settings - Fork 31
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
require that inputs be plain objects (or arrays of) #133
require that inputs be plain objects (or arrays of) #133
Conversation
@@ -41,7 +41,6 @@ expectType<{ foo_bar: boolean }[]>(snakecaseKeys([{ fooBar: true }])); | |||
expectAssignable<Array<{ [key: string]: boolean }>>( | |||
snakecaseKeys([{ fooBar: true }]) | |||
); | |||
expectType<string[]>(snakecaseKeys(["name 1", "name 2"])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the unsupported array format test.
@bendrucker, I would appreciate your confirmation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead and separate the documentation and type concerns since I'm left unsure as to whether there's any legitimate issue here.
I do not put TypeScript in readmes as ultimately these are intended as JavaScript packages and should meet that lowest common denominator. The types given are JS pseudo-code. I do accept PRs with user-contributed types but TypeScript fluency should not be required to read the docs.
If you want to drop support for arrays you'll need to do more to make the case for that breaking change and make the change comprehensively. Obviously it's a bit silly to try to snake case an array of strings. Presumably this was a possible path because arrays are objects in JS and could be passed to map-obj
without erroring. Dropping support for arrays also means the JavaScript code should also reject them.
@@ -29,9 +29,9 @@ snakecaseKeys({'foo-bar': true, nested: {fooBaz: 'bar'}}); | |||
##### obj | |||
|
|||
*Required* | |||
Type: `object` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an informal pseudo-JS notation. I am not trying to use TypeScript types here. See exclude
for example.
Happened to be peeking at map-obj for another PR This happened well after I started using map-obj. Sindre went with a patch. This is one of the many ambiguous semver cases where it's strictly breaking but you can surely argue that "this wasn't supposed to work." I also haven't updated map-obj since v5 is ESM only though, so you'd still have to implement the array checking here until/if I get around to an ESM conversion that can apply the patch to the aforementioned issue. |
@bendrucker , Thank you for your review. Are you sure that you want to follow the following steps to correct this issue?
|
Yeah, let's do this in multiple distinct steps if possible for clarity. If there's any changes you think should be made right now to the TypeScript definitions, based on what the JS code supports, please send that as one PR. If the TS already accurately reflects the inputs that the underlying JS implementation supports, no change is needed here. Separately, you can send another PR dropping support for arrays, which will involve both TS and JS changes. The TS definition can make arrays a compile error, but also the JS should reject arrays with a |
3384901
to
abca2b5
Compare
@bendrucker, sorry for the late reply, I have changed the PR to fix the TS type definitions as a set with the JS code fixes. |
Thanks for your work on this! Out of caution I'm going to release this as a new major version since both the JS and typing changes have potential to break people's code. |
I think this may have introduced a bug with arrays. This test no longer functions, because it throws
Most likely the check for the array input type should be
|
This resolves the issue #121.
I am updating the README to match the TypeScript type definitions.
Then update
any[]
toReadonlyArray<Record<string, unknown>>
to accept only the key-value record type of the array.