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

TS2345 Argument of type A is not assignable to parameter of type A #9358

Closed
CarsonF opened this issue Jun 25, 2016 · 2 comments
Closed

TS2345 Argument of type A is not assignable to parameter of type A #9358

CarsonF opened this issue Jun 25, 2016 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@CarsonF
Copy link

CarsonF commented Jun 25, 2016

TypeScript Version:

1.8.0

Code

declare function decorate<T>(): (component: T) => T;

class Foo {
  derp () {}
}

decorate<Foo>()(Foo);
error TS2345: Argument of type 'typeof Foo' is not assignable to parameter of type 'Foo'.
  Property 'derp' is missing in type 'typeof Foo'.

How can there be a type mismatch if it's the same type? 😖

@yortus
Copy link
Contributor

yortus commented Jun 25, 2016

Your decorate<Foo>() call returns a function that accepts and returns an instance of Foo, but then you pass it the constructor function Foo, which is not the same type, hence the error.

I'm not sure whether you mean to work with Foo instances or Foo constructors, but the following variants both pass type checks:

decorate<typeof Foo>()(Foo);  // Foo constructor
decorate<Foo>()(new Foo);  // Foo instance

@CarsonF
Copy link
Author

CarsonF commented Jun 25, 2016

@yortus Ahh thank you, that's what I was missing.

Thank you @blakeembrey as well :)

@CarsonF CarsonF closed this as completed Jun 25, 2016
@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jun 26, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants