how to declare type of function property returned on object

Leahcim

When function f is called, it returns bar, so that I can then call bar.baz(). However, typescript complains that Property baz does not exist on type (selection: any) => () => void How can I declare the baz property of bar to make this compile?

   var f = function foo(){
        function bar(selection : any){
        }
        bar.baz = function(value){

        }
        return bar 
    }

(as an aside, I have this code inside an angular2 typescript project and it's very unforgiving. Other typescript projects I've worked on allow you to ignore the typescript errors, but this angular starter project really won't compile so I'm stuck until the typescript issue is resolved)

nsnze

do you mean this?

interface foo {
    (selection: any): void;
    baz: (value) => void;
}
var f = function () {
    var bar: foo = function (selection: any) {
    } as any
    bar.baz = function (value) {
    }
    return bar
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to access a property of an object which is returned from a function using javascript?

From Dev

How can I declare the type of a class property?

From Dev

How to declare the type of a function that returns an array in Fortran?

From Dev

How to declare function return type `int (*)[3]`?

From Dev

How to declare function return type `int (*)[3]`?

From Dev

How do I declare a object for use with this function

From Dev

How to declare function that returns an array of object?

From Dev

Why is the "then" property automatically accessed on an object returned from an async function?

From Dev

Declare type of a object key

From Dev

Swagger 2.0: How to declare a definition property of type model?

From Dev

How can I declare a templated class type as a member method, *not* a property?

From Dev

Expression as function parameter for property and object type

From Dev

How to pass a function an object and a property

From Dev

How do I declare a property of a record as an abstract function

From Dev

How can one declare a function using a function type in GO

From Dev

How to declare a property as a subclass

From Dev

How to set a property of a class to be returned by default for an object/class?

From Dev

How to get jquery returned value to a property of model object in Razor Page

From Dev

TypeScript: How to type a returned function's return type

From Dev

How to access a function of an object that was returned as a pointer by another function.

From Dev

In Processing.js, how to declare an object type and an array of objects?

From Dev

How to declare the type of an object to be any class but not primitive types

From Dev

How to declare an ArrayList of specified type using Class object

From Dev

How to declare an ArrayList of specified type using Class object

From Dev

How can I declare the Type of a Variable in a Julia Object?

From Dev

Why function as an object property not accessing the closure when object is created using 'new' and returned immediately?

From Dev

How can I declare the type of a function defined within a let

From Dev

How to declare a Kotlin function with return type 'void' for a java caller?

From Dev

How to explicitly declare a cv::Mat type as part of a OpenCV library function

Related Related

  1. 1

    How to access a property of an object which is returned from a function using javascript?

  2. 2

    How can I declare the type of a class property?

  3. 3

    How to declare the type of a function that returns an array in Fortran?

  4. 4

    How to declare function return type `int (*)[3]`?

  5. 5

    How to declare function return type `int (*)[3]`?

  6. 6

    How do I declare a object for use with this function

  7. 7

    How to declare function that returns an array of object?

  8. 8

    Why is the "then" property automatically accessed on an object returned from an async function?

  9. 9

    Declare type of a object key

  10. 10

    Swagger 2.0: How to declare a definition property of type model?

  11. 11

    How can I declare a templated class type as a member method, *not* a property?

  12. 12

    Expression as function parameter for property and object type

  13. 13

    How to pass a function an object and a property

  14. 14

    How do I declare a property of a record as an abstract function

  15. 15

    How can one declare a function using a function type in GO

  16. 16

    How to declare a property as a subclass

  17. 17

    How to set a property of a class to be returned by default for an object/class?

  18. 18

    How to get jquery returned value to a property of model object in Razor Page

  19. 19

    TypeScript: How to type a returned function's return type

  20. 20

    How to access a function of an object that was returned as a pointer by another function.

  21. 21

    In Processing.js, how to declare an object type and an array of objects?

  22. 22

    How to declare the type of an object to be any class but not primitive types

  23. 23

    How to declare an ArrayList of specified type using Class object

  24. 24

    How to declare an ArrayList of specified type using Class object

  25. 25

    How can I declare the Type of a Variable in a Julia Object?

  26. 26

    Why function as an object property not accessing the closure when object is created using 'new' and returned immediately?

  27. 27

    How can I declare the type of a function defined within a let

  28. 28

    How to declare a Kotlin function with return type 'void' for a java caller?

  29. 29

    How to explicitly declare a cv::Mat type as part of a OpenCV library function

HotTag

Archive