- 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.
推薦閱讀
- OpenStack Cloud Computing Cookbook(Third Edition)
- Learning Neo4j
- 深度實(shí)踐OpenStack:基于Python的OpenStack組件開(kāi)發(fā)
- C++ Builder 6.0下OpenGL編程技術(shù)
- SQL Server 2012數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用(微課版·第5版)
- Learning ASP.NET Core 2.0
- PostgreSQL技術(shù)內(nèi)幕:事務(wù)處理深度探索
- Mastering Python Scripting for System Administrators
- Spring Boot Cookbook
- Serverless computing in Azure with .NET
- Learning Apache Karaf
- INSTANT Yii 1.1 Application Development Starter
- PHP編程基礎(chǔ)與實(shí)踐教程
- Extending Unity with Editor Scripting
- SQL Server 2016 從入門(mén)到實(shí)戰(zhàn)(視頻教學(xué)版)