-
Notifications
You must be signed in to change notification settings - Fork 734
Closed
Description
Code being compiled:
class Project {
constructor(
public name: string,
public deadline: Date,
public budget: number
) {}
extendDeadline(days: number): void {
this.deadline.setDate(this.deadline.getDate() + days);
}
}
const p = new Project("new app", new Date(), 1000);
console.log(p);
Expected:
class Project {
name;
deadline;
budget;
constructor(name, deadline, budget) {
this.name = name;
this.deadline = deadline;
this.budget = budget;
}
extendDeadline(days) {
this.deadline.setDate(this.deadline.getDate() + days);
}
}
const p = new Project("new app", new Date(), 1000);
console.log(p);
/* outputs:
Project {
name: 'new app',
deadline: 2025-03-12T19:10:10.994Z,
budget: 1000
}
*/
Actual:
class Project {
constructor(name, deadline, budget) { }
extendDeadline(days) {
this.deadline.setDate(this.deadline.getDate() + days);
}
}
const p = new Project("new app", new Date(), 1000);
console.log(p);
/* outputs:
Project {}
*/
Ref doc: https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties
Metadata
Metadata
Assignees
Labels
No labels