Skip to content

Instantly share code, notes, and snippets.

View logentries-gists's full-sized avatar

logentries-gists

View GitHub Profile
// Declaring a simple interface that has 2 public properties x and y
interface Point {
x: Number;
y: Number;
}
function getGreaterAxisValue(point: Point) {
return (point.x > point.y) ? point.x : point.y;
}
getGreaterAxisValue({ x: 10, y: 30 }); // return 30
getGreaterAxisValue({ x: 20, y: 3 }); // return 20
// Declaring a simple interface that has 2 public properties x and y
interface Point {
x: Number;
y: Number;
}
class Point2D implements Point {
x: Number;
y: Number;
constructor(x: Number, y: Number) {
this.x = x;
this.y = y;
}
}
class Point3D extends Point2D {
z: Number;
constructor(x: Number, y: Number, z: Number) {
super(x, y);
this.z = z;
}
}
class MyCustomWindow {
constructor() {
window.onmousedown = function(e) {
console.log(this.toString())
};
window.onmousemove = (e) => {
console.log(this.toString())
};
}
toString() {
function logme(name: String, age) {
console.log(“I am ${name} and I am ${age} years old”);
}
function logmeAgain(name: String, age: Numm) {
console.log(“I am ${name} and I am ${age} years old”);
}
// In both execution, I will get the same result
// >> I am Danilo and I am 32 years old
logme(“Danilo”, 32);
logme(“Danilo”, “32”);
let calc = {
operation: “sum”,
operator1: 23,
operator2: 41
}, ops = [23, 41];
let {operator1, operator2, operation} = calc;
console.log(operator1, operator2, operation); // >> 23 41 sum
function sum({operator1, operator2 }) {
return operator1 + operator2;
}
sum(calc);
console.log(sum(calc)); // >> 64
console.log(sum(…ops)); // >> 64
const Hello = ({greeting = ‘Hello’}) => <div>{greeting}</div>;
let example = <Hello name=’TypeScript 1.8’ />;