JavaScript type validation does not consider ES6 "extends" keywords?
Hi,
I'm recently migrating my JS code from ES5 to ES6.
In doing this, I define subclasses using ES6 "extends" keyword, instead of @extends JSDoc annotations.
Then, IDEA does not recognize a defined class (Sub_Es6Syntax in the code below) as a subclass of the base class (Base), and displays a warning on the editor.
This warning disappears if I add an @extends annotation to the definition of Sub_Es6Syntax, but it seems redundant for me.
Is it possible to use only "extends" keyword without any warnings?
Environment:
- IntelliJ IDEA 2018.2.2, Build #IU-182.4129.33, macOS
- JavaScript Language Version=ECMAScript6 in Preferences > Languages & Frameworks > JavaScript
/**
* Base class
*/
Base = function() {};
/**
* Subclass defined using JSDoc
* @extends {Base}
*/
Sub_JsDoc = function() {};
/**
* Subclass defined using ES6 syntax
*/
class Sub_Es6Syntax extends Base {}
/**
* Some function
* @param {Base} a
*/
function f(a) {}
f(new Sub_JsDoc()); // no warning
f(new Sub_Es6Syntax()); // !! "Argument type Sub_Es6Syntax is not assignable to parameter type Base"
Please sign in to leave a comment.
Extending ES5 classes using ES6 syntax is not currently supported. Please follow https://youtrack.jetbrains.com/issue/WEB-28080 for updates
Thanks Elena, I'm awaiting updates :)