The in-operator is used to check whether a property within an object with a particular interface type exists or not.
interface ILaptop { brand : string; user? : string; year? : number; } let laptop1 : ILaptop = { brand : "Dell", } function nameOfLaptop(obj : ILaptop) { if ("brand" in obj) { console.log(obj.brand) } } nameOfLaptop(laptop1)
As you can see the “brand” property does exist within the above object with the type ILaptop and thus the brand of that object will be printed on the terminal screen!