Skip to content

Instantly share code, notes, and snippets.

@floydawong
Created February 28, 2018 12:47
Show Gist options
  • Save floydawong/f9cc425b7566da848df2bc36bc50f353 to your computer and use it in GitHub Desktop.
Save floydawong/f9cc425b7566da848df2bc36bc50f353 to your computer and use it in GitHub Desktop.
TS_interface
// 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