HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.2k stars 658 forks source link

Enhancement request: js.Promise<Void> (or similar) #6793

Open jcward opened 6 years ago

jcward commented 6 years ago

Separated this out of the conversation in #6790:

As long as we're thinking about js.Promise, it'd be nice if you could have a Promise<Void> (or just Promise), where resolve() and then(callback) expect no arguments. I know it's features like this that balloon the complexity, but I'm just saying -- it'd be nice. Otherwise I'm forced to write ugly crufty code like:

new Promise<Dynamic>
resolve(null);
.then(function(ignore) { });

Cludgy Dynamic, useless null, and empty ignore -- all terrible conventions.

Maybe it'd be possible with abstract EmptyPromise (Promise)?

Maybe @elsassph / @kevinresol have some thought?

@jdonaldson commented:

Here's some typescript folks struggling with the same issue: Microsoft/TypeScript#8516 Microsoft/TypeScript#3356 Microsoft/TypeScript#4260 DefinitelyTyped/DefinitelyTyped#6091

jdonaldson commented 6 years ago

One more small aside : I ran into this same problem with promhx, but didn't have a great solution there either. I believe @back2dos handled this in tink by passing a dummy value.

nadako commented 6 years ago

well, modern languages use "functional" approach of having an universal Unit value :)

jdonaldson commented 6 years ago

A rose by any other name would smell as sweet.

jdonaldson commented 6 years ago

I bet we could solve this with abstracts.™

ncannasse commented 6 years ago

While I agree this would be a nice goal, this is quite hard to deal with it tbh, because in a lot of cases (hxcpp for instance, but not only), there is a clear runtime difference between an argument of type T and 0 arguments, so when you start dealing with generics it becomes a lot harder.

On Fri, Dec 22, 2017 at 9:26 AM, Alexander Kuzmenko < notifications@github.com> wrote:

Maybe this can be handled in the compiler such as generic fields/properties which becomes typed as Void could not be accessed?

class Some { var value:T; function new() {}

static function main() { var some = new Some(); trace(some.value); //Error: Void field could not be accessed. } }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/haxe/issues/6793#issuecomment-353548187, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-bwFNKzBUVM7d6ZtMdOd9ixl2fPzpDks5tC2fLgaJpZM4RKJYz .

elsassph commented 6 years ago

We're talking about nicer handling of JS APIs.

kevinresol commented 6 years ago

This is how I deal with it: https://github.com/haxe-react/haxe-react-native/blob/master/src/Nothing.hx

RealyUniqueName commented 6 years ago

Myabe we should use @kevinresol's until a proper solution is implemented? Maybe add Nothing to haxe.Constraints