"undefined" type support in generics

Topics: Language Specification
Jul 3, 2014 at 10:51 PM
WebIDL presentation of WritableStream interface uses Promise<undefined> to present a Promise that returns nothing.
interface WritableStream {
    // Generic properties
    Promise<unsigned long long> write (any data, optional [Clamp] unsigned long long costOverride);
    Promise<unsigned long long> awaitSpaceAvailable ();
    Promise<undefined>          writeClose ();
    Promise<undefined>          writeAbort (optional any reason);
    // Binary data specific properties
                attribute DOMString writeEncoding;
TS does not support undefined in type arguments, so we have to write it as Promise<any>. There would be several use cases of Promise<undefined> as it would be useful when no result data is required, while I couldn't find more examples in other W3C specifications.

I think this is worth to be discussed if there is no proper workaround other than using any type.
Jul 4, 2014 at 12:20 AM
Edited Jul 4, 2014 at 12:20 AM
Why not use the "void" no-type type. ;)
Jul 4, 2014 at 5:21 AM
Oh??? I thought I have tried it and it didn't work, but it now works perfectly. Maybe I was too sleepy :/

Thank you :)
Jul 4, 2014 at 7:25 AM
Edited Jul 4, 2014 at 7:25 AM
Void type Promise now accepts void typed parameter as its return value, which is somewhat weird... hmm. Anyway it works.