class Todo {
private _date: Date;
public name: string;
constructor(todo: Todo) {
this._date = todo._date;
this.name = todo.name;
}
get date() { ... }
}
// example
const todos = Agent.fetchTodos();
const modifiedTodos1 = map.todos(todo => new Todo(todo)); // works fine
const modifiedTodos2 = map.todos(todo => new Todo( { ...todo, _date: new Date() } )); // doesn't work
The second modifiedTodos2 line of code gives me the following error: property date is missing in type [...]
In my scenario, I'm required to use the spread operator to extend the todo object with an additional prop. But I'm not sure why I'm seeing this error and how to deal with it...
and I also can't make the date optional with ? operator.
Thank you so much in advance for pointing out why my scenario doesn't work and what to do to make it work!
get date() { ... }is restricting the creation of additional properties or at least is setting the attrdateas a required property.