Skip to content

Instantly share code, notes, and snippets.

@tamert
Created September 12, 2021 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamert/d381e905ec7d50dbbfd59c074b8e5338 to your computer and use it in GitHub Desktop.
Save tamert/d381e905ec7d50dbbfd59c074b8e5338 to your computer and use it in GitHub Desktop.
Partial
interface Book {
id: number;
title: string;
subject: 'crime' | 'comedy';
body: string;
}
class BookRepository {
constructor(private model: Book) {}
update( model: Partial<Book> ) {
// Update model
this.model = Object.assign(this.model, model);
console.log(this.model);
}
}
let book: BookRepository = new BookRepository({
id: 13,
subject: 'crime',
title: 'Arsène Lupin, Gentleman Burglar',
body: 'Leblanc`s creation, gentleman thief Arsène Lupin, is everything you would expect from a French aristocrat - witty, charming, brilliant, sly ... and possibly the greatest thief in the world.'
});
book.update({
subject: 'comedy'
});
/**
* {
"id": 13,
"subject": "comedy",
"title": "Arsène Lupin, Gentleman Burglar",
"body": "Leblanc`s creation, gentleman thief Arsène Lupin, is everything you would expect from a French aristocrat - witty, charming, brilliant, sly ... and possibly the greatest thief in the world."
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment