[2
本教程继续我们的打字稿初学者系列,并在先前介绍打字稿功能,安装和IDE建议的基础上。 第二个教程涵盖的打字稿数据类型及其预防误差的好处。
x
andPoint (with
width), and
Cuboid (extending
Point with
length and
height), help define object structures.
cuboid 示例演示了所有属性的指定值,并使用函数来计算卷。
至关重要的是要注意接口是特定于打字稿的功能,在JavaScript中不存在。 编译打字稿代码在以下JavaScript等效中产生:
rountedrectangle
本教程为打字稿界面提供了基础,强调了它们在编写强大代码中的作用。 您已经学会了创建具有可选和仅阅读属性的接口,并利用索引签名来添加超出初始接口定义的动态属性。 要深入了解,请参阅官方的打字稿文档。function volumeCuboid(cuboid) { let volume = cuboid.length * cuboid.width * cuboid.height; console.log(`Volume: ${volume}`); } let cuboid = { x: -22, y: 28, width: 12, length: 32, height: 20 }; volumeCuboid(cuboid); // Volume: 7680
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3