Skip to content

Instantly share code, notes, and snippets.

@Swalloow
Created July 10, 2018 12:28
Show Gist options
  • Save Swalloow/c8fe5e9d4eea4e6233a6557dc6493b14 to your computer and use it in GitHub Desktop.
Save Swalloow/c8fe5e9d4eea4e6233a6557dc6493b14 to your computer and use it in GitHub Desktop.
Typescript Partial<T>
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