Created
February 28, 2018 12:47
-
-
Save floydawong/f9cc425b7566da848df2bc36bc50f353 to your computer and use it in GitHub Desktop.
TS_interface
This file contains 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
// interface | |
interface Shape { | |
name: string; | |
width: number; | |
height: number; | |
color?: string; | |
} | |
function area(shape: Shape) { | |
var area = shape.width * shape.height; | |
return "I'm " + shape.name + " with area " + area + " cm squared"; | |
} | |
console.log(area({ name: "rectangle", width: 30, height: 15 })); | |
console.log(area({ name: "square", width: 30, height: 30, color: "blue" })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment