July 2019
Intermediate to advanced
416 pages
10h 6m
English
In the ConsolidatedGrid example from the Intersection types section, we assigned each property to our intersection individually. Depending on the effect that we are trying to achieve, there is another way that we could have created our <Grid & Margin> intersection type with less code. Using a spread operator, we could perform a shallow copy of the properties from one or more of our input types automatically.
First, let's see how we can rewrite our earlier example so that it automatically populates the margin information:
function ConsolidatedGrid(grid : Grid, margin : Margin) : Grid & Margin { let consolidatedGrid = <Grid & Margin>{...margin}; consolidatedGrid.Width += grid.Width; consolidatedGrid.Height ...Read now
Unlock full access