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

Partial-izing the template does not behave as expected #15169

Closed
ktalebian opened this issue Apr 13, 2017 · 1 comment
Closed

Partial-izing the template does not behave as expected #15169

ktalebian opened this issue Apr 13, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@ktalebian
Copy link

ktalebian commented Apr 13, 2017

Here is an interface that takes in two templates. the returned function should be a partial of one of the templates (this is a take on the React-Redux):

export type IState<TState, TOwnProps> = {
    connect: (mapStateToProps: MapStateToProps<TState, Partial<TOwnProps>>) => any;
}
export type MapStateToProps<TState, TProps> = (state: TState) => TProps;

Now, here is the example of a state that would want to use this:

interface IAppState {
    services: string[]
}
    
interface IAppProps {
    services: string[];
    count: number;
}
    
const MyState: IState<IAppState, IAppProps>;
MyState.connect(
    (state) => {
        return {
            services: state.services,
            foo: null
        }
    }
);

MyState.connect should expect one function (which it does). The argument should be of type IAppState (which it is). But the return is suppose to be a Partial<IAppProps>. However, as you can see I am returning foo: null too and the service is not complaining about this.

What am I doing wrong here?

@mhegazy
Copy link
Contributor

mhegazy commented Apr 14, 2017

This is not specific to map types, or Partial. the excess property checks (that should catch foo as an extra property) do not run on return positions of contextually typed functions. #12632 tracks that.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 14, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants