Skip to content

Instantly share code, notes, and snippets.

@CheatEx
Last active January 31, 2019 08:31
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 CheatEx/4f771744bd393bd305660846c10df016 to your computer and use it in GitHub Desktop.
Save CheatEx/4f771744bd393bd305660846c10df016 to your computer and use it in GitHub Desktop.
class Message {
greeting: string;
body: string;
data: number;
constructor(greeting: string, body: string, data: number) {
this.greeting = greeting;
this.body = body;
this.data = data;
}
//already sucks - triple repetition
}
type Greeting = Message & { name: string;}
let m: Message = new Message("hey", "im a message", 42);
function doActualStuff(g: Greeting): void {
console.log(g.name);
}
let g = m;
g.name = "Vasya";
g.anotherFieldNeededElsewhere = true;
doActualStuff(g);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment