Argument must extend class

Ohgodwhy

I'm moving to Typescript for a variety of reasons, and so far I'm supremely happy with it.

One of the issues that I've ran into is verifying that an argument passed to a function extends another class.

For instance:

class Foo {
    public $xyz
}

class Bar {
    constructor(model: extends Foo)
}

class Baz extends Foo {}

Many classes can extend foo, besides Baz, but they all have the same properties. I need to ensure that the class being passed to the model argument of the constructor Bar correctly extends Foo.

How can I achieve this?

(please forgive the terrible psuedo-code above)

If my approach is wrong, I'd love to hear what I could do to solve that problem as well.

Igor
constructor(model: Foo)

Is what you are looking for. This states that the passed instance model is of type Foo or inherits from Foo.

The keyword extends can only be used in type declarations to denote that the type extends (inherits from) another type.

See also Classes documentation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Extend a class with private constructer

From Java

Extend data class in Kotlin

From Java

Extend class Firestore

From Dev

"Template argument for template template parameter must be a class template or type alias template"

From Dev

extend a class to conform to an interface?

From Dev

Member variable which must extend class A and implement some interface

From Dev

TypeError: unbound method 'method name' must be called with 'class name' instance as first argument (got str instance instead)

From Dev

Can I have a class field that is the Class<?> of a type that must extend another class and an interface?

From Dev

Extend Blueprint class?

From Dev

Laravel extend Form class

From Dev

RestyGWT content argument must be a class

From Dev

How to extend a Singleton class

From Dev

How do you extend a class using composition which requires a more specialized constructor argument?

From Dev

Extending abstract method with generic parameter (that must extend generic class) in Java

From Dev

Where must the argument be checked

From Dev

Trying to extend an EJB from a Generic Class: IllegalArgumentException The Argument {0} is not a valid local client view for the EJB {1}

From Dev

ERROR mapping.DefaultUrlMappingEvaluator$UrlMappingBuilder - URL mapping argument [exception] with value [(*)] must be a valid class

From Dev

Realm model classes must either extend RealmObject or implement RealmModel to be considered a valid model class

From Dev

Argument must be a string in nodejs

From Dev

twitteR R Package OAuth issue: Error in registerTwitterOAuth(cred) : oauth argument must be of class OAuth

From Dev

ERROR: unbound method "method name" must be called with "Class Name" instance as first argument (got classobj instance instead)

From Dev

Member variable which must extend class A and implement some interface

From Dev

"Template argument for template template parameter must be a class template or type alias template"

From Dev

Sass - @extend mixin, change an argument

From Dev

Trying to extend an EJB from a Generic Class: IllegalArgumentException The Argument {0} is not a valid local client view for the EJB {1}

From Dev

Java - Extend a class that extend a Thread class

From Dev

Array argument must be ByRef

From Dev

Specify that a Class argument must implement a particular interface

From Dev

zip argument #1 must support iteration on class object list

Related Related

  1. 1

    Extend a class with private constructer

  2. 2

    Extend data class in Kotlin

  3. 3

    Extend class Firestore

  4. 4

    "Template argument for template template parameter must be a class template or type alias template"

  5. 5

    extend a class to conform to an interface?

  6. 6

    Member variable which must extend class A and implement some interface

  7. 7

    TypeError: unbound method 'method name' must be called with 'class name' instance as first argument (got str instance instead)

  8. 8

    Can I have a class field that is the Class<?> of a type that must extend another class and an interface?

  9. 9

    Extend Blueprint class?

  10. 10

    Laravel extend Form class

  11. 11

    RestyGWT content argument must be a class

  12. 12

    How to extend a Singleton class

  13. 13

    How do you extend a class using composition which requires a more specialized constructor argument?

  14. 14

    Extending abstract method with generic parameter (that must extend generic class) in Java

  15. 15

    Where must the argument be checked

  16. 16

    Trying to extend an EJB from a Generic Class: IllegalArgumentException The Argument {0} is not a valid local client view for the EJB {1}

  17. 17

    ERROR mapping.DefaultUrlMappingEvaluator$UrlMappingBuilder - URL mapping argument [exception] with value [(*)] must be a valid class

  18. 18

    Realm model classes must either extend RealmObject or implement RealmModel to be considered a valid model class

  19. 19

    Argument must be a string in nodejs

  20. 20

    twitteR R Package OAuth issue: Error in registerTwitterOAuth(cred) : oauth argument must be of class OAuth

  21. 21

    ERROR: unbound method "method name" must be called with "Class Name" instance as first argument (got classobj instance instead)

  22. 22

    Member variable which must extend class A and implement some interface

  23. 23

    "Template argument for template template parameter must be a class template or type alias template"

  24. 24

    Sass - @extend mixin, change an argument

  25. 25

    Trying to extend an EJB from a Generic Class: IllegalArgumentException The Argument {0} is not a valid local client view for the EJB {1}

  26. 26

    Java - Extend a class that extend a Thread class

  27. 27

    Array argument must be ByRef

  28. 28

    Specify that a Class argument must implement a particular interface

  29. 29

    zip argument #1 must support iteration on class object list

HotTag

Archive