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
| // 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 |
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
| // Declaring a simple interface that has 2 public properties x and y | |
| interface Point { | |
| x: Number; | |
| y: Number; | |
| } |
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 Point2D implements Point { | |
| x: Number; | |
| y: Number; | |
| constructor(x: Number, y: Number) { | |
| this.x = x; | |
| this.y = y; | |
| } | |
| } |
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 Point3D extends Point2D { | |
| z: Number; | |
| constructor(x: Number, y: Number, z: Number) { | |
| super(x, y); | |
| this.z = z; | |
| } | |
| } |
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 MyCustomWindow { | |
| constructor() { | |
| window.onmousedown = function(e) { | |
| console.log(this.toString()) | |
| }; | |
| window.onmousemove = (e) => { | |
| console.log(this.toString()) | |
| }; | |
| } | |
| toString() { |
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
| 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”); |
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
| let calc = { | |
| operation: “sum”, | |
| operator1: 23, | |
| operator2: 41 | |
| }, ops = [23, 41]; |
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
| 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 |
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
| console.log(sum(…ops)); // >> 64 |
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
| const Hello = ({greeting = ‘Hello’}) => <div>{greeting}</div>; | |
| let example = <Hello name=’TypeScript 1.8’ />; |
OlderNewer