Argument type is not assignable to parameter type when passing child


I'm new to JavaScript and PHPStorm.

I have object A and B where B.prototype = new A();

Then I have a function and pass new B object as argument and it generates:
Argument type B is not assignable to parameter type A warning.

From what I understand JS is not a statically typed language and my warning has to do with:
* @param {A}
before declaration of function in question.

The PHPStorm doesn't seem to recognize that B is a child of A and produces the warning.

Now, in my actual code I don't use .prototype but instead something like:
B = A.extend('GameScene', { } );
And I imagine that complicates things.

My question is of course how do I not get this warnings?

1 comment

You should use @extends tag where inheritance is not recornized, e.g.

var A = function() {} /** @extends A */ var B = A.extend("GameScene", {}); /** @param {A} x */ function f(x) {} f(new B()); // no warnings here

Inheritance is recognized with statement B.prototype = new A(), so no tag is required here. And please note, that you should use parameter name after type with @param tag. See


Please sign in to leave a comment.