Created
September 12, 2021 13:39
-
-
Save tamert/d381e905ec7d50dbbfd59c074b8e5338 to your computer and use it in GitHub Desktop.
Partial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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