[WebIDL] A new way to define UnionTypes

Hi!

I was wondering if it would make sense to use supplemental interfaces as a
way to generate union types, like in this example:
X implements S
Y implements S
Z implements S

interface someInterface
{
	NewSyntaxGeneratingUnionTypeFrom(S) someMethod();
}

The example assumes the user agent defines the interfaces X, Y, Z that
implement the same supplemental interface S. In such case,
NewSyntaxGeneratingUnionType(S) will expand (literally or conceptually,
depends on the UA) to the union type (X or Y or Z).

Having this syntax makes it easy to define functions that will definitely
return objects adhering to a certain interface but are not necessary
containing S in the prototype chain.

A real life use case for this is the Region interface [1]. Right now, the
only interface implementing Region is Element. The plan is to also allow
pseudo elements [2] implement the Region interface. Because Element and
CSSPseudoElement are totally different types it is impossible to define a
method that returns a "Region" (e.g. NamedFlow.getRegions() [3]). This new
syntax would permit writing the method without worrying about the future
interfaces that will also implement Region as supplemental.

Thoughts?

Thanks,
Andrei.

[1] http://www.w3.org/TR/css3-regions/#the-region-interface
[2] 
http://adobe.github.com/css-pseudo-elements/docs/css4-pseudoelements.html#m
ozTocId993453
[3] http://www.w3.org/TR/css3-regions/#dom-named-flow-get-regions

Received on Wednesday, 29 August 2012 12:00:18 UTC