W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2012

[WebIDL] A new way to define UnionTypes

From: Andrei Bucur <abucur@adobe.com>
Date: Wed, 29 Aug 2012 12:59:44 +0100
To: "public-webapps@w3.org" <public-webapps@w3.org>
Message-ID: <CC63DEE0.37BA7%abucur@adobe.com>

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.



[1] http://www.w3.org/TR/css3-regions/#the-region-interface
[3] http://www.w3.org/TR/css3-regions/#dom-named-flow-get-regions
Received on Wednesday, 29 August 2012 12:00:18 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:38 UTC