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

PR #2467 breaks TS interface inheritance #2483

Closed
lukescott opened this issue Jun 29, 2017 · 4 comments
Closed

PR #2467 breaks TS interface inheritance #2483

lukescott opened this issue Jun 29, 2017 · 4 comments

Comments

@lukescott
Copy link

lukescott commented Jun 29, 2017

Do you want to request a feature or report a bug?

Bug

export default mapHandlers<SingleChoice>({
	select(state, {value}: SelectAction) {
		return input(state, value)
	},

	reset(state) {
		return input(state, "")
	},

	validate(state) {
		return input(state, state.value)
	},
import {Action, Reducer} from "redux"

export type HandlerMapObject<S> = {
	[name: string]: Reducer<S>
}

export default
function mapHandlers<S>(
	handlers: HandlerMapObject<S>,
	defaultReducer?: Reducer<S>
): Reducer<S> {
	return (state, action) => {
		const reducer = handlers[action.type] || defaultReducer
		if (reducer !== undefined) {
			return reducer(state, action)
		}
		return state
	}
}

screen shot 2017-06-29 at 1 59 30 pm

What is the current behavior?

Argument of type '{ select(state: SingleChoice, { value }: SelectAction): SingleChoice; reset(state: SingleChoice):...' is not assignable to parameter of type 'HandlerMapObject<SingleChoice>'. Property 'select' is incompatible with index signature. Type '(state: SingleChoice, { value }: SelectAction) => SingleChoice' is not assignable to type 'Reducer<SingleChoice>'. Types of parameters '__1' and 'action' are incompatible. Type 'AnyAction' is not assignable to type 'SelectAction'. Property 'value' is missing in type 'AnyAction'.

What is the expected behavior?

No errors.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?

master - error
3.7.1 - works

This was caused by PR #2467

@lukescott
Copy link
Author

lukescott commented Jun 29, 2017

Looks like the reason for the change was there was an issue w/ <A extends Action> part, but this works:

export type Reducer<S> = (state: S, action: Action) => S

@lukescott lukescott reopened this Jun 29, 2017
@lukescott lukescott changed the title PR #2467 broke TS interface inheritance PR #2467 breaks TS interface inheritance Jun 29, 2017
@timdorr
Copy link
Member

timdorr commented Jun 29, 2017

What version of TS are you using?

@lukescott
Copy link
Author

@timdorr 2.4.1. Sorry, I had some information incorrect. I updated the original issue.

@lukescott
Copy link
Author

Gah, sorry. I actually got it to work with AnyAction. I broke something while trying to debug the original issue I was having, which was related to the TypeScript version.

Either of these work as well though:

export type Reducer<S> = (state: S, action: Action) => S
export type Reducer<S, A extends Action = Action> = (state: S, action: Action) => S

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

2 participants