Skip to content

Optional parameter - assignment problem #20858

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

Closed
lluzak opened this issue Dec 22, 2017 · 1 comment
Closed

Optional parameter - assignment problem #20858

lluzak opened this issue Dec 22, 2017 · 1 comment

Comments

@lluzak
Copy link

lluzak commented Dec 22, 2017

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; }>'.
@j-oliveras
Copy link
Contributor

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

@lluzak lluzak closed this as completed Jan 5, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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