-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
// Given:
interface Foo {
simpleMember: number;
optionalMember?: string;
objectMember: X; // Where X is a inline object type, interface, or other object-like type
}
// This:
var foo: partial Foo;
// Is equivalent to:
var foo: {simpleMember?: number, optionalMember?: string, objectMember?: X};
// And this:
var bar: deepPartial Foo;
// Is equivalent to:
var foo: {simpleMember?: number, optionalMember?: string, objectMember?: deepPartial X};
Potential Use Cases
- Mongo Queries (
deepPartial
) React.setState
(partial
)
amir-arad, TheTedAdams, alitaheri, mquandalle, alerkesi and 83 moredenis-sokolov, flq, aaronbeall, gaspard, netanelgilad and 22 more
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
DanielRosenwasser commentedon Sep 21, 2015
I brought this up recently with @mhegazy, and it can really come in handy, especially
And I'm sure in other scenarios. How we choose to go about making this available is a separate matter.
s-panferov commentedon Sep 21, 2015
Just for bookkeeping, it's the same as $Shape from #2710.
Gaelan commentedon Sep 21, 2015
@s-panferov Does
$Shape
matchdeepPartial
orpartial
? (deepPartial
is recursive for sub-objects)kitsonk commentedon Sep 21, 2015
And type guard against anything that isn't actually in the interface.
I would suspect
$Shape
could matchpartial
at the least if notdeepPartial
(e.g. a non-strict object literal check).Why wouldn't the behaviour always just be like
deepPartial
... If you are already in the mode of not being strict, why would you ever suddenly not want that to be deep?Gaelan commentedon Sep 21, 2015
@kitsonk I was thinking of
React.setState
, or any other function that overwrites keys of one object with keys from another, not recursing.jbondc commentedon Sep 22, 2015
This would work nicely:
fredgalvao commentedon Sep 23, 2015
This would make typings for lodash/underscore pretty awesome.
Would also be usefull in cases where you get a partial model as a param on the constructor to build the actual model. This way we wouldn't need to create a sibling interface just to hold the same properties with different optionality.
dallonf commentedon Oct 12, 2015
Yes, this would be extremely handy! Another good use case is React "higher-order" components - I want to implement a component that acts just like another, "lower-order" component, except it automatically calculates the value of some of its props... example time:
DomBlack commentedon Oct 29, 2015
Yet another use case would be backbone models which have defaults and the constructor takes a partial set of attributes which override the defaults:
jbrantly commentedon Oct 29, 2015
@DomBlack just pointed me to this. Thanks! Just for backward/forward reference, this was also discussed in #392.
Strate commentedon Nov 11, 2015
+1
xogeny commentedon Nov 14, 2015
+1
For me, the big benefit of such functionality would be in being able to create typesafe APIs around the various libraries for immutable data structures like
updeep
orimmutable.js
. In both of these libraries, the efficiency of the library hinges on being able to modify data structures by passing in the "deltas" you wish to apply. And the fundamental issue with type safety is a way of expressing the types of these deltas in the context of a parametric type for the complete data.Of course, some basic language level functionality for implementing or expressing lenses would also be a potential way of addressing the issue.
102 remaining items