-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 Schema's clone function typing #10951
Conversation
Before: clone returns an untyped schema After: clone returns a typed schema which can be the original type or a type that extends the base type (would work for type extending it with partial params)
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'm supportive of adding a generic param to clone()
, but I'm not sure making clone()
return something other than this
is the right call. For one thing, you're missing a bunch of generic parameters to Schema
. And I can confirm that this
respects generics
Can't we do clone<T = this>(): T
?
I agree, but then T should ensure to extend |
Unfortunately not. 2 reasons: 1) |
@vkarpov15 ah! interesting, do you happen to have any docs on why extends causes such perf issues? thanks for the link |
Wish I knew, but I'm not experienced enough with TS internals to know why sometimes |
Summary
The Schema's clone function does not preserve the typing (and on its best case, it loses the name of the type and just types the cloned schema as a nameless object)
Examples
Before:
clone returns an untyped schema (or at best it returns an object but the type name/interface/class is lost)
After:
clone returns a typed schema which can be the original type or a type that extends the base type (would work for type extending it with partial params)