microsoft / microsoft/TypeScript
TS2409 is an invalid error.
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript code sample and investigate how constructor return types are checked against the class instance type. Compare the reported TS2409 behavior with JavaScript's constructor-return semantics; done means the intended valid case is accepted without weakening unrelated constructor checking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100