Skip to content

Optional parameter - assignment problem #20858

Closed
@lluzak

Description

@lluzak

Problem comes from react-redux package when using ```connect`` function.

TypeScript Version: 2.6.2

Code

interface F {
  a?: number;
}

interface P {
  a?: number;
}

const u: P = { a: undefined };
const v = { a: u.a };

class C extends React.Component<F, {}> {
  constructor(p: F) {
    super(p);
  }

  render() {
    return <div>Hello</div>;
  }
}

interface IGC<Y> {
  <P extends Y>(component: React.ComponentClass<P>): React.ComponentClass<P>;
}

interface IGB<K extends any = any> {
  <K>(p: K): IGC<K>;
}

const gb: IGB = p => {
  return function(Componentklass) {
    return Componentklass;
  };
};

let y = gb(v);
y(C);

Expected behavior:

Allow to assign optional property into it equivalent number | undefined

Actual behavior:

    TS2345: Argument of type 'typeof C' is not assignable to parameter of type 'ComponentClass<{ a: number | undefined; }>'.
        Type 'C' is not assignable to type 'Component<{ a: number | undefined; }, ComponentState>'.
            Types of property 'props' are incompatible.
                  Type 'Readonly<{ children?: ReactNode; }> & Readonly<F>' is not assignable to type 'Readonly<{ children?: ReactNode; }> & Readonly<{ a: number | undefined; }>'.
                          Type 'Readonly<{ children?: ReactNode; }> & Readonly<F>' is not assignable to type 'Readonly<{ a: number | undefined; }>'.
                                    Property 'a' is optional in type 'Readonly<{ children?: ReactNode; }> & Readonly<F>' but required in type 'Readonly<{ a: number | undefined; }>'.

Activity

j-oliveras

j-oliveras commented on Dec 22, 2017

@j-oliveras
Contributor

Duplicate of #12400? (seams like will be solved into typescript 2.8)

locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @lluzak@j-oliveras

        Issue actions

          Optional parameter - assignment problem · Issue #20858 · microsoft/TypeScript