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

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

Closed
yenshih opened this issue Jul 15, 2017 · 2 comments
Closed

Comments

@yenshih
Copy link

yenshih commented Jul 15, 2017

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'.

@SimonMeskens
Copy link

Why aren't you just using any instead of AnyAction, since they are exactly the same? I don't understand why AnyAction exists at all when you typed it to mean: "objects that are assignable to this interface can have any properties".

Is it just because AnyAction gives you code completion for "type"?

In any case, I wouldn't want the language to allow this as it would make indexed types useless (they would all turn into type any)

@yenshih
Copy link
Author

yenshih commented Jul 15, 2017

That's exactly what I thought!
I'd like make a PR to @types/redux repo. THANKS :)

@yenshih yenshih closed this as completed Jul 15, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants