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

[TS] Type safety is not good enough when using $ngRedux.connect() #207

Open
arutkowski00 opened this issue Aug 29, 2018 · 0 comments
Open

Comments

@arutkowski00
Copy link
Contributor

Hello,
let me present you some code to start with:

import { INgRedux } from 'ng-redux';

import { RootState } from '../';

import * as actions from './actions';
import * as selectors from './selectors';

export class FooController implements ng.IController {
  readonly bar: ReturnType<typeof selectors.getBar>;
  readonly fooBar: ReturnType<typeof selectors.getFooBar>;

  readonly load: typeof actions.load;
  readonly save: typeof actions.save;

  /* @ngInject */
  constructor(private $ngRedux: INgRedux) {
    $ngRedux.connect((state: RootState) => ({
      bar: selectors.getBar(state),
      fooBar: selectors.getFooBar(state),
    }), actions)(this);
  }
}

As you can clearly see, I have to repeat declarations twice: once, in $ngRedux.connect() and second, in the controller to be type-safe. If, for some reason, I start refactoring this code, by changing names of properties in connect() or changing the action creators' names imported in ./actions, this code will not throw any compilation error.

Question: is there a way to improve type-safety with $ngRedux.connect()? Maybe connect() should limit properties/actions in map***ToTarget to only those that are declared in the controller?

@arutkowski00 arutkowski00 changed the title [TS} Type safety is not good enough with connect() [TS] Type safety is not good enough when using $ngRedux.connect() Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant