google / google/closure-compiler
Cannot specify return type for class constructor
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
The compiler complains if the return type of a class constructor is not strictly an instance of this constructor. (Since I upgrade from the august version to v20181008).
As javascript allows to return anything from a constructor, the compiler should allow users to specify a custom return type using the "@return" doc.
Just for example if I do:
```
class Translator
{
/**
* Constructor with custom return type.
*
* @return {Promise.}
*/
constructor()
{
return this.bootstrap();
}
/**
* @return {Promise.}
*/
async bootstrap()
{
return this;
}
}
```
I don't want to get this warning:
```
Translator.js:10: WARNING - inconsistent return type
found : Promise
required: Translator
return this.bootstrap();
^^^^^^^^^^^^^^^^
```
Contributor guide
Assessment
This issue has not been assessed yet.