Skip to content
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 some way of specifying a 'fragment type' #5398

Closed
Meowtimer opened this issue Oct 25, 2015 · 2 comments
Closed

Allow some way of specifying a 'fragment type' #5398

Meowtimer opened this issue Oct 25, 2015 · 2 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@Meowtimer
Copy link

React's setState(state) method accepts an object with only some of the total set of keys found in a component's state but to express that in Typescript the definition of the interface passed to React.Component[Props, State] has to be somewhat sacrificed by making all fields optional (?):

interface State { stateField1?: number; stateField2?: number; }
class MyComponent extends React.Component<any, State> {
... this.setState({ stateField1: 123 }); ...
}

Better IMO would be to have some way of specifying that the argument to setState is a 'fragment' of State.

class Component<Props, State> {
  ...
  setState(update: fragmentof State);
}

interface State { stateField1: number; stateField2: number; }
var s: State = { stateField1: 123 }; // ts error
this.setState({ stateField1: 123 }); // ts ok
@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Oct 26, 2015
@ivogabe
Copy link
Contributor

ivogabe commented Oct 26, 2015

Looks like the same suggestion as #4889

@mhegazy
Copy link
Contributor

mhegazy commented Oct 26, 2015

Yup, looks like a duplicate. thanks @ivogabe

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Oct 26, 2015
@mhegazy mhegazy closed this as completed Oct 26, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants