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

fix: assert.typeof(xxx, 'object') should assert record or null #603

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

michaelfig
Copy link
Member

This refinement makes the assertion meaningful (before it was just asserting the equivalent of any).

@michaelfig michaelfig requested a review from erights March 7, 2021 07:42
@michaelfig michaelfig self-assigned this Mar 7, 2021
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the reasoning for any over unknown in this case?

@michaelfig
Copy link
Member Author

What’s the reasoning for any over unknown in this case?

Turns out that using Record<any, any> | null is the only combination that gives the proper type narrowing one would expect assert.typeof(xxx, 'object') to do. It's by no means perfect, but provides the features I need to use assert.typeof to eliminate non-matching type possibilities.

It narrows to the intersection of the type with any kind of object (including arrays, etc) or null.

Unfortunately I was never able to find a way to have it type the same as assert(typeof xxx === 'object'). Schade.

@michaelfig michaelfig merged commit c84ba97 into master Mar 8, 2021
@michaelfig michaelfig deleted the mfig-assert-typing branch March 8, 2021 00:30
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