-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow super
constrains for type parameters
#7265
Comments
Is there a public API that follows this pattern? |
This looks similar to #6613, see #7079 (comment) |
Yeah, sounds like React's class Component<Props, State> {
setState<T, State extends T>(state: T);
} |
Indeed, very much like React's setState problem. In my particular case, I have the following function:
That works wonderfully. But then I have a utility function built on top of make_model_from that allows specification of a constrained set of overrides:
Does that make sense? |
looks like what you want is a #6613 (comment) so your send_messafe would be something like: function send_message<T super typeof message_model>(overrides: T = null) {
const new_message = make_model_from(message_model, overrides ? overrides : {});
} |
super
constrains for type parameters
Tracking the general issue of |
@RyanCavanaugh not sure if #7004 is the same issue. That seems to be more about reusing the JSX TypeScript feature for Angular Templates. Support for optionality of React state (and other scenarios) seems to be close by using f-bounded polymorphism. The support doesn't seem consistent (it works in a function, but not in a method - see here for an example #6613 (comment)). @ahejlsberg suggests that this is by design in #7079, but I don't see how it does work in a regular function and not in a method. As I mention in #6613, this has become more of a pain in Typescript 2.0 because making your state members all optional forces massive code changes when using strict null checks. |
I'd like to be able to express constraints in a generic function the opposite direction as
extends
. For example, I'd like to write something like:That is, T cannot have any fields not in Foo.
The text was updated successfully, but these errors were encountered: