let price: number let isValid: boolean let username: string function calcTax(country: string, price: number, unit: number): number{ return price * unit * 0.1 } let tax = calcTax("aa", 2000, 5)
interface Rectangle { kind: "四角形", width: number, height: number } interface Circle { kind: "¥", radius: number } type Shape = Rectangle | Circle function area(shape: Shape){ switch(shape.kind){ case "四角形": return shape.height * shape.width case "円": return shape radius * shape.radius * Math.PI } } const myRectangle: Rectangle = { kind: "四角形", width: 100, height: 30 } const myCircle: Circle = { kind: "円", radius: 50 } console.log(area(myCircle))