Skip to content

PR #2467 breaks TS interface inheritance #2483

@lukescott

Description

@lukescott

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions