-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
🔎 Search Terms
class
this
object spread syntax
type inference
🕗 Version & Regression Information
The issue occurs in 5.8.3, as well as the oldest version the Playground supports (3.3.3) and the current nightly version in the Playground.
⏯ Playground Link
💻 Code
class test {
public fieldA: number;
public fieldB: number;
constructor(a: number, b: number) {
this.fieldA = a;
this.fieldB = b;
}
public a(): number {
return 1;
}
public improperInference() {
// improperly inferred to be `this`
const z = { ...this };
return z;
}
public properInference() {
const q = new test(1, 2);
// properly inferred to be `{ fieldA: number; fieldB: number; }`
const z = { ...(this as typeof q) };
return z;
}
}
🙁 Actual behavior
const z = { ...this }
is inferred to be this
🙂 Expected behavior
const z = { ...this }
should be inferred to be a POJO with fields matching the public fields of the class.
(Actually it should also infer the protected
and private
fields. They're accessible from this
and so should be visible at this point.)
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created