Skip to content

Instantly share code, notes, and snippets.

@samwx
Last active July 6, 2019 19:02
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 samwx/f1ecbf2ee1e6d6cba832deefc12392ba to your computer and use it in GitHub Desktop.
Save samwx/f1ecbf2ee1e6d6cba832deefc12392ba to your computer and use it in GitHub Desktop.
Typescript examples
function SelfDriving(classFn: Function) {
classFn.prototype.selfDrivable = true;
}
@SelfDriving
class SomeCar {
private make: string;
constructor(make: string) {
this.make = make;
}
}
function Wheels(numberOfWheels: number) {
return function(classFn: Function) {
classFn.prototype.wheels = numberOfWheels;
}
}
@Wheels(3)
class ExoticCar {
private make: string;
constructor(make: string) {
this.make = make;
}
}
export class MailSender<T> {
send(mail: T) {
console.log('Sending...', mail);
}
}
const billing = new MailSender<CardBilling>();
billing.send(new CardBilling());
interface IAnimal {
name: string;
sound: () => string;
run: () => number;
}
class Dog implements IAnimal {
name: string;
constructor(name: string) {
this.name = name;
}
run() {
return 30;
}
sound() {
return 'auau';
}
}
type Person = {
firstName: string;
lastName: string;
country: string;
};
function f(): Person {
return {
firstName: 'Samuel',
lastName: 'Martins',
country: 'Brasil',
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment