-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
When the return type of a function is the this type, uses of that function should preserve the type information of the left hand operand.
See example:
class TestClass {
constructor(public member: number) { }
fakeCopy() {
return this;
}
copy() {
return new TestClass(this.member);
}
}
const tester: Readonly<TestClass> = new TestClass(5);
tester.member = 6; // This properly errors.
tester.copy().member = 6; // This properly does not error.
tester.fakeCopy().member = 6; // This should error.In this example fakeCopy returns a TestClass; it would be more intuitive if fakeCopy would return typeof tester which would be Readonly<TestClass>
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug