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

see if tassign is still relevant with later typescript versions #400

Closed
SethDavenport opened this issue May 20, 2017 · 3 comments
Closed
Labels

Comments

@SethDavenport
Copy link
Member

SethDavenport commented May 20, 2017

object spread is supported now; check out how its typings work. If it makes sense, adjust the 'strongly typed reducers' article

@SethDavenport
Copy link
Member Author

potentially deprecate tassign if that makes sense too

@e-schultz
Copy link
Member

Quickly playing around in the TypeScript repl...

interface State {
  name: string;
  age: number;
  nickName: string;
}

let reducer = (state: State, action): State => {
  switch (action.type) {
    case 'ONE':
      return { ...state, x: 'y' }; // isn't an error - objects returned by spread don't care about extra params
    default:
      return state;
  }
  
}
interface State {
  name: string;
  age: number;
  nickName: string;
}

let reducer = (state: State, action): State => {
  switch (action.type) {
    case 'ONE':
        return { x: 'hi', name: '', age: 0, nickName: 'bob' } // this would complain due to 'x'  not being on State
    default:
      return state;
  }
  
}

Some discussion around this in the TypeScript repo - #10727 - and some design notes around this behaviour is in Design Meeting Notes, 12/16/2016

There is also an issue for Exact Types which is in proposal that seems like it'd solve this.

Someone linked to spread operations with exact types - guide is geared towards react-redux, but demos using Partial's .

but the tl;dr I guess - until the Exact proposal gets implemented - still value in tassign.

@SethDavenport
Copy link
Member Author

OK cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants