Created
July 10, 2018 12:28
-
-
Save Swalloow/c8fe5e9d4eea4e6233a6557dc6493b14 to your computer and use it in GitHub Desktop.
Typescript Partial<T>
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
class Person { | |
public name: string = "default" | |
public address: string = "default" | |
public age: number = 0; | |
public constructor(init?:Partial<Person>) { | |
Object.assign(this, init); | |
} | |
} | |
let persons = [ | |
new Person(), | |
new Person({}), | |
new Person({name:"John"}), | |
new Person({address:"Earth"}), | |
new Person({age:20, address:"Earth", name:"John"}), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment