Skip to content

Gracefully handle "property is missing in interface with index signature"? #17223

Closed
@yenshih

Description

@yenshih

TypeScript Version: 2.4.1

Code

import { combineReducers } from 'redux'
import { routerReducer as router } from 'react-router-redux'

const rootReducer = combineReducer<IState>({
    router,
    ...otherReducers
})

/*
export interface Action {
  type: any;
}
export interface AnyAction extends Action {
  // Allows any extra properties to be defined in an action.
  [extraProps: string]: any;
}
export interface RouterAction extends Action {
    type: typeof CALL_HISTORY_METHOD;
    payload: LocationActionPayload;
}

Error:
Type 'AnyAction' is not assignable to type 'RouterAction'.
Property 'payload' is missing in type 'AnyAction'.
*/

Expected behavior:
Maybe no error?
I'm not sure if there's any graceful solution to this problem, I mean without using 'any' type assertion.
Actual behavior:
Type 'AnyAction' is not assignable to type 'RouterAction'.
Property 'payload' is missing in type 'AnyAction'.

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