@@ -71,7 +71,7 @@ export abstract class Capability<P extends string = string>
7171 return this ;
7272 }
7373
74- public diff ( capability : Capability < P > ) {
74+ public diff ( capability : Capability < P > , fallbackToFirstOfType ?: boolean ) {
7575 const instance = new ( Object . getPrototypeOf ( this ) . constructor ) (
7676 this . definition ,
7777 this . universalProperties ,
@@ -81,7 +81,7 @@ export abstract class Capability<P extends string = string>
8181 . getPropertiesArray ( )
8282 . reduce < Property [ ] > ( ( properties , property ) => {
8383 if ( this . hasProperty ( property . name as P ) ) {
84- const ref = this . findProperty ( property ) ;
84+ const ref = this . findProperty ( property , fallbackToFirstOfType ) ;
8585 if ( ref && ref . equals ( property ) ) {
8686 return properties ;
8787 }
@@ -188,10 +188,15 @@ export abstract class Capability<P extends string = string>
188188 return property ;
189189 }
190190
191- public findProperty ( property : Property ) : Property | undefined {
191+ public findProperty ( property : Property , fallbackToFirstOfType ?: boolean ) : Property | undefined {
192192 if ( this . hasProperty ( property . name as P ) ) {
193193 if ( property . multiple ) {
194- return this . getProperties ( property . name as P ) . find ( ( ref ) => ref . isInstanceOf ( property ) ) ;
194+ const match = this . getProperties ( property . name as P ) . find ( ( ref ) =>
195+ ref . isInstanceOf ( property ) ,
196+ ) ;
197+ return match === undefined && fallbackToFirstOfType
198+ ? this . getProperty ( property . name as P )
199+ : match ;
195200 } else {
196201 return this . getProperty ( property . name as P ) ;
197202 }
@@ -226,9 +231,9 @@ export abstract class Capability<P extends string = string>
226231 return this ;
227232 }
228233
229- public update ( capability : Capability < P > ) {
234+ public update ( capability : Capability < P > , fallbackToFirstOfType ?: boolean ) {
230235 return capability . getPropertiesArray ( ) . reduce ( ( result , property ) => {
231- const ref = this . findProperty ( property ) ;
236+ const ref = this . findProperty ( property , fallbackToFirstOfType ) ;
232237
233238 if ( ref ) {
234239 ref . replace ( property ) ;
0 commit comments