Skip to content

Instantly share code, notes, and snippets.

@tamert
Created September 12, 2021 14:35
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/225e7293350d515e28908168b204abff to your computer and use it in GitHub Desktop.
Save tamert/225e7293350d515e28908168b204abff to your computer and use it in GitHub Desktop.
Required
interface Book {
id: number;
title: string;
subject?: 'crime' | 'comedy';
body: string;
}
class BookRepository {
constructor(private model: Book | {} = {}) {}
create( model: Required<Book> ) {
// Create model
this.model = Object.assign(this.model, model);
console.log(this.model);
}
}
let book: BookRepository = new BookRepository();
book.create({
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.'
});
/**
* {
"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