- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 83字
- 2021-07-15 17:05:31
Optional properties using an interface
In some scenarios, we may want to pass values only for minimal parameters. In such cases, we can define the properties in an interface as optional properties, as follows:
interface Customer { id: number; name: string; bonus?: number; } function addCustomer(customer: Customer) { if (customer.bonus) { console.log(customer.bonus); } } addCustomer({id: 101, name: "Rajesh Gunasundaram"});
Here, the bonus property has been defined as an optional property by concatenating a question mark (?) at the end of the name property.
推薦閱讀
- Visual Basic程序設計教程
- C#程序設計(慕課版)
- Python Network Programming Cookbook(Second Edition)
- 單片機應用與調試項目教程(C語言版)
- Scientific Computing with Scala
- Symfony2 Essentials
- Learning Raspbian
- 零基礎趣學C語言
- Unity 2017 Mobile Game Development
- Geospatial Development By Example with Python
- Hands-On JavaScript for Python Developers
- Magento 2 Beginners Guide
- Mastering VMware Horizon 7(Second Edition)
- DB2SQL性能調優秘笈
- Mastering Unreal Engine 4.X