Skip to content

feat: Add isPartialRecord guard#50

Open
kkirsche wants to merge 8 commits intolazarljubenovic:masterfrom
kkirsche:feat/isRecord
Open

feat: Add isPartialRecord guard#50
kkirsche wants to merge 8 commits intolazarljubenovic:masterfrom
kkirsche:feat/isRecord

Conversation

@kkirsche
Copy link
Copy Markdown
Contributor

@kkirsche kkirsche commented Jan 20, 2023

This begins to address #4 but is no longer a full solution.

@kkirsche kkirsche changed the title feat: Support isRecord feat: Support isRecord Jan 20, 2023
@kkirsche kkirsche changed the title feat: Support isRecord feat: Add isRecord guard (fixes #4) Jan 20, 2023
@lazarljubenovic
Copy link
Copy Markdown
Owner

This doesn't work correctly. The simplest example is for an empty object: you'll always return true, because the array of key/value pairs you're checking is empty. In TypeScript, Record is exhaustive: the object of type Record<'a' | 'b' | 'c', number> required all three keys to exist, but you function will return true as long as each existing satisfies the predicate. For example, {} will pass, but it should not.

Unfortunately, I don't think there's an easy to fix it properly. The only thing we can do is assert that an object is of type Partial<Record<K, V>>, but this should be properly documented and reflected in the function name to avoid confusion.

@kkirsche
Copy link
Copy Markdown
Contributor Author

kkirsche commented Mar 8, 2023

I'm happy to either close this due to this limitation or update it to be isPartialRecord, do you have a preference which direction is gone?

@lazarljubenovic
Copy link
Copy Markdown
Owner

I guess leaving it but renaming it is the way to go. At least we'll have a function, which is better than nothing!

@kkirsche
Copy link
Copy Markdown
Contributor Author

kkirsche commented Mar 8, 2023

Rebased against master and I've renamed the function to isPartialRecord, updated the guard and the comment

@kkirsche
Copy link
Copy Markdown
Contributor Author

kkirsche commented Mar 8, 2023

😄 well, at least the github actions workflows are protecting things

@kkirsche kkirsche changed the title feat: Add isRecord guard (fixes #4) feat: Add isPartialRecord guard Mar 8, 2023
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.

2 participants