Skip to content

Conversation

@aikoven
Copy link
Collaborator

@aikoven aikoven commented Jul 25, 2016

Introduce more strict typings for compose function to allow smarter inference, e.g.:

import {compose} from "redux";
import {connect} from "react-redux";
import {withRouter} from "react-router";

compose(
  withRouter,
  connect(
    (state, ownProps) => {
      return {
        foo: 'bar',
      };
    }
  )
)(props => {
  // `props` type is inferred to `{foo: string, router: Router}`
});

cc @ulfryk, @Igorbek

@ulfryk
Copy link

ulfryk commented Jul 25, 2016

@aikoven - this PR is a proof that React and Redux where designed for dynamically typed world…

Anyway it looks GOOD 👍

@aikoven
Copy link
Collaborator Author

aikoven commented Jul 25, 2016

@ulfryk Things will get better with support for variadic kinds in TS :)

* `(...args) => f(g(h(...args)))`.
*/
export function compose(): <R>(a: R, ...args: any[]) => R;
export function compose(): <R>(a: R) => R;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overload will hide the next one. Is it allowed for compose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! My bad, didn't notice it has no parameters.

@Igorbek
Copy link
Contributor

Igorbek commented Jul 26, 2016

Thank you for adding me as a reviewer. Besides of minor concern (see comment), it looks good to me.

@timdorr
Copy link
Member

timdorr commented Jul 26, 2016

@ulfryk Things will get better with support for variadic kinds in TS :)

Will this have any backwards-compatibility concerns?

Sounds like everyone who knows TS is in agreement on this. In she goes!

(side note: I really need to learn TS...)

@timdorr timdorr merged commit 085eaec into reduxjs:master Jul 26, 2016
@aikoven
Copy link
Collaborator Author

aikoven commented Jul 27, 2016

@timdorr

@ulfryk Things will get better with support for variadic kinds in TS :)

Will this have any backwards-compatibility concerns?

I guess so, older versions of TS compiler won't be able to consume new typings. However, as far as I can see, new versions are adopted very fast by the community.

If the problem get serious (e.g. there would be a lot of projects not being able to migrate quickly to the new TS compiler), there are some workarounds. For example, we can have a separate repo for older version typings. It's very easy to substitute official typings coming with NPM package by some external ones.

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

Successfully merging this pull request may close these issues.

4 participants