-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: add isClass
function
#239
base: main
Are you sure you want to change the base?
feat: add isClass
function
#239
Conversation
Benchmark Results
Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure. |
isClass
function isClass
function
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.
Thank you for this 😎
I tweaked the Class
type and the return type of isClass
to be even more robust. Also added more “type test” cases.
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
Hey! There's a new requirement for PRs that introduce new features. Without this requirement met, we won't be able to merge this. Note that this PR can still be included in a
|
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm add radashi@pr<PR_NUMBER>
.Summary
Add the
isClass
functionIn the documentation, I emphasized that this function primarily validates whether a value is a custom class using the
class
syntax, rather than checking if the value is compatible withnew
. If we wanted to handle all cases of instantiable objects, including old-school function-based classes and “native classes”, we should implement separate functions for these cases. This function does not account for function constructors or native classes that can still be instantiated withnew
.If we were to address this, we could consider implementing a separate utility, perhaps using an approach like this: https://www.npmjs.com/package/isclass?activeTab=code
Related issue, if any:
For any code change,
Does this PR introduce a breaking change?
No
Bundle impact
src/typed/isClass.ts
Footnotes
Function size includes the
import
dependencies of the function. ↩