typescript - intersection type



If you want to defined your type which contains intersection of properties but nothing else then you can use & operator.

In this example we define, CrazyMix which must defined bread, crust, size properties.
If we introduce another property, then we will get an error.



interface IPizza {
crust : string,
size : number
}

interface ISandwich {
bread : string
size : number
}

type MixFood = IPizza & ISandwich

const CrazyMix : MixFood = {
bread : 'i want ',
crust : 'test',
size : 100
}


const CrazyMix : MixFood = {
bread : 'i want ',
crust : 'test',
size : 100
rating : 10 // ERROR
}











Comments

Popular posts from this blog

PySpark - Working with JDBC Sqlite database