You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Indeed, very much like React's setState problem. In my particular case, I have the following function:
export function make_model_from<T, U extends T>(instance: U, overrides: T) {
let override_props = {} as any;
for (let k in overrides) {
override_props[k] = { enumerable: true, value: overrides[k] };
}
let rv = Object.create(instance, override_props);
Object.freeze(rv);
return rv;
}
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:
// I'd like to constrain overrides to so its fields are restricted to a subset of MessageModel.
// I don't think you can spell that in TypeScript today.
function send_message(overrides = null) {
const new_message = make_model_from(message_model, overrides ? overrides : {});
Ryan Cavanaugh (@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)). Anders Hejlsberg (@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.
Activity
RyanCavanaugh commentedon Feb 26, 2016
Is there a public API that follows this pattern?
mhegazy commentedon Feb 26, 2016
This looks similar to #6613, see #7079 (comment)
vsiao commentedon Feb 26, 2016
Yeah, sounds like React's
setStateproblem:chadaustin commentedon Feb 27, 2016
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?
mhegazy commentedon Mar 28, 2016
looks like what you want is a #6613 (comment)
so your send_messafe would be something like:
[-]Constraining type parameter to a set of fields[/-][+]Allow `super` constrains for type parameters[/+]RyanCavanaugh commentedon May 9, 2016
Tracking the general issue of
setState/ JSX property modifications at #7004 since these seem to be the same scenariojoewood commentedon Jul 27, 2016
Ryan Cavanaugh (@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)). Anders Hejlsberg (@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.