TS2409 is an invalid error.
See original GitHub issueTypeScript Version: 3.3.0-dev.20181222
Search Terms: TS2409
Code
class A {
constructor() {
// return an arrow function
return message => {
this._message = message;
return this;
};
}
bar() {
console.log(this._message);
}
}
const a = new A();
a('hello world').bar(); // 'hello world'
Expected behavior: No error.
Actual behavior: src/test.ts(4,5): error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
I should be able to override the object returned from a constructor.
Normally constructors don’t return a value, but they can choose to do so if they want to override the normal object creation process.
Souce: MDN - new operator
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Return type of constructor signature must be assignable to the ...
compilation is good but with this type error :TS2409: Return type of constructor signature must be assignable to the instance type of the ......
Read more >Error & Warning Details - typegoose
This Error may get thrown when a invalid Type is used with the option enum . Currently Valid Types for enum are String...
Read more >CreateWorldGenerationJobResponse | RoboMaker Client - AWS ...
The specified resource could not be found. RequestThrottled. The request was throttled. InvalidInput. An input parameter in the request is not valid.
Read more >ERROR_CODE_TYPE | Video SDK v1.3.1_3.1 API Reference for ...
1115: Audio device module: AudioRecord returns error. ... Defined in agora.ts:2409 ... The token is invalid due to one of the following reasons:....
Read more >googleapis documentation - Google Cloud
Defined in src/apis/privateca/v1beta1.ts:2409. Parameters : ... Requests specifying an invalid value will be rejected. Requests for policies with any ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Real life example where returning something other that
this
is actually very helpful is when we want to make the constructor of aclass T
async. Due to the nature of how async/await is implemented, the constructor would need to return aPromise<T>
instead ofT
.However Typescript complains that ‘Return type of constructor signature must be assignable to the instance type of the class.’ while I believe it should not indicate the above method of returning a
Promise<T>
as erroneous.@weswigham I believe you’re mistaken. Class constructors cannot return other primitives. They can however return Objects.