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

update combineReducers typings for ts 2.1 #2231

Closed
wants to merge 2 commits into from
Closed

update combineReducers typings for ts 2.1 #2231

wants to merge 2 commits into from

Conversation

Rendalf
Copy link

@Rendalf Rendalf commented Feb 5, 2017

Since TypeScript corresponds keyof and Lookup Types we can check shape of passed reducers map.

Next code is valid in current version, but invalid with updated typings.

type A = number
type B = string
type MyState = {
  a: A
  b: B
}

const reducerA: Reducer<A> = (state = 0, action) => {
  ...
}

const reducerB: Reducer<B> = (state = 'hello', action) => {
  ...
}

export default combineReducers<MyState>({
  x: reducerA,
})

Updated typings will check shape of combineReducers properly.

...
export default combineReducers<MyState>({
  a: reducerA,
  b: reducerB,
})

@timdorr
Copy link
Member

timdorr commented Feb 5, 2017

How prevalent is TS 2.1 usage? I don't want to break others' usage of these typings if they haven't upgraded TS.

(This is exactly what I don't like about having typings in the source repo, btw)

@aikoven
Copy link
Collaborator

aikoven commented Feb 6, 2017

Already merged into the next branch: #2182

@timdorr Switching typings for 2.1 would always be a breaking change. Unfortunately there are little alternatives to bundling typings with Redux.

To publish typings to @types NPM org one has to add them to DefinitelyTyped mono-repo, but this makes them quite inconvenient to maintain.

Another option is to publish them as a separate NPM package, but then TS won't be able to automatically discover it and users would have to explicitly link their compilation to that package like this: #2182 (comment). This also introduces a risk of fragmentation if no single package is considered official.

That said, the current situation already makes us use explicit linking (as in #2182 (comment)) until the next major release, which I don't expect to happen soon.

I'd propose to put typings in a separate GitHub repo under https://github.com/reactjs/, publish as a separate NPM package, and make a link to it in Redux readme.

There's an ongoing discussion that would hopefully let us link that package with @types someday: microsoft/types-publisher#4

@Rendalf
Copy link
Author

Rendalf commented Feb 6, 2017

Thanks to @aikoven for explanation

Won't be merged because it already exists into the next branch

@Rendalf Rendalf closed this Feb 6, 2017
@Rendalf Rendalf deleted the update-ts-typings branch February 6, 2017 09:29
@timdorr
Copy link
Member

timdorr commented Feb 6, 2017

Thanks for the insight, @aikoven!

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.

3 participants