Error: Cannot invoke an expression whose type lacks a call signature

Justin

I am brand new to typescript, and I have two classes. In the parent class I have:

abstract class Component {
  public deps: any = {};
  public props: any = {};

  public setProp(prop: string): any {
    return <T>(val: T): T => {
      this.props[prop] = val;
      return val;
    };
  }
}

In the child class I have:

class Post extends Component {
  public toggleBody: string;

  constructor() {
    this.toggleBody = this.setProp('showFullBody');
  }

  public showMore(): boolean {
    return this.toggleBody(true);
  }

  public showLess(): boolean {
    return this.toggleBody(false);
  }
}

Both showMore and ShowLess give me the error, "Cannot invoke an expression whose type lacks a call signature."

But the function that setProp returns DOES have a call signature, I think? I think I'm misunderstanding something important about typings of functions, but I don't know what it is.

Thanks!

SLaks

The function that it returns has a call signature, but you told Typescript to completely ignore that by adding : any in its signature.

Don't do that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot invoke an expression whose type lacks a call signature TypeScript error

From Java

Cannot invoke an expression whose type lacks a call signature

From Dev

typescript Cannot invoke an expression whose type lacks a call signature?

From Dev

Typescript Compiler Cannot invoke an expression whose type lacks a call signature

From Dev

Cannot invoke an expression whose type lacks a call signature, map

From Dev

error TS2349: Cannot invoke an expression whose type lacks a call signature

From Dev

TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature

From Dev

Promises with typescript-2.x gives error :Cannot invoke an expression whose type lacks a call signature

From Dev

Cannot invoke an expression whose type lacks a call signature. Type has no compatible call signatures

From Dev

Cannot invoke an expression whose type lacks a call signature, while it has a signature

From Dev

How to fix "TS2349: Cannot invoke an expression whose type lacks a call signature"

From Dev

Typescript cannot invoke expression whost type lacks a call signature

From Dev

TypeScript: Cannot use 'new' with an expression whose type lacks a call or construct signature

From Dev

TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. Mongoose

From Dev

How do I fix "Cannot use 'new' with an expression whose type lacks a call or construct signature" in angular 4?

From Java

object[] | object[] type lacks a call signature for 'find(),foreach()'

From Dev

Exporting typescript function "lacks a call signature"

From Dev

Exporting typescript function "lacks a call signature"

From Dev

Type declaration file and call signature error

From Dev

Type declaration file and call signature error

From Dev

Cannot invoke + with an argument of type CGRect error in Swift

From Dev

Error "Type IFoo<T> requires a construct signature but type Foo<T> lacks one" when implementing a newable generic interface in TypeScript

From Dev

Cannot invoke value of type

From Dev

SKNode subclass generates error: cannot invoke initializer for type "X" with no arguments

From Dev

Swift compiler error: “Cannot invoke 'map' with an argument list of type '((_) -> _)'”

From Dev

Swit map: error: cannot invoke 'map' with an argument list of type '((_) -> _)'

From Dev

Java Error : cannot invoke size() on the primitive type double

From Dev

Swift compiler error: Cannot invoke 'lockForConfiguration' with an argument list of type '(() -> ())'

From Dev

Swift: Updated and got error: "cannot invoke '!=' with argument list of type.."

Related Related

  1. 1

    Cannot invoke an expression whose type lacks a call signature TypeScript error

  2. 2

    Cannot invoke an expression whose type lacks a call signature

  3. 3

    typescript Cannot invoke an expression whose type lacks a call signature?

  4. 4

    Typescript Compiler Cannot invoke an expression whose type lacks a call signature

  5. 5

    Cannot invoke an expression whose type lacks a call signature, map

  6. 6

    error TS2349: Cannot invoke an expression whose type lacks a call signature

  7. 7

    TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature

  8. 8

    Promises with typescript-2.x gives error :Cannot invoke an expression whose type lacks a call signature

  9. 9

    Cannot invoke an expression whose type lacks a call signature. Type has no compatible call signatures

  10. 10

    Cannot invoke an expression whose type lacks a call signature, while it has a signature

  11. 11

    How to fix "TS2349: Cannot invoke an expression whose type lacks a call signature"

  12. 12

    Typescript cannot invoke expression whost type lacks a call signature

  13. 13

    TypeScript: Cannot use 'new' with an expression whose type lacks a call or construct signature

  14. 14

    TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. Mongoose

  15. 15

    How do I fix "Cannot use 'new' with an expression whose type lacks a call or construct signature" in angular 4?

  16. 16

    object[] | object[] type lacks a call signature for 'find(),foreach()'

  17. 17

    Exporting typescript function "lacks a call signature"

  18. 18

    Exporting typescript function "lacks a call signature"

  19. 19

    Type declaration file and call signature error

  20. 20

    Type declaration file and call signature error

  21. 21

    Cannot invoke + with an argument of type CGRect error in Swift

  22. 22

    Error "Type IFoo<T> requires a construct signature but type Foo<T> lacks one" when implementing a newable generic interface in TypeScript

  23. 23

    Cannot invoke value of type

  24. 24

    SKNode subclass generates error: cannot invoke initializer for type "X" with no arguments

  25. 25

    Swift compiler error: “Cannot invoke 'map' with an argument list of type '((_) -> _)'”

  26. 26

    Swit map: error: cannot invoke 'map' with an argument list of type '((_) -> _)'

  27. 27

    Java Error : cannot invoke size() on the primitive type double

  28. 28

    Swift compiler error: Cannot invoke 'lockForConfiguration' with an argument list of type '(() -> ())'

  29. 29

    Swift: Updated and got error: "cannot invoke '!=' with argument list of type.."

HotTag

Archive