Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 05:52
    eamodio opened #34554
  • 04:19
    typescript-bot synchronize #33940
  • 02:08
    shrinktofit closed #34410
  • 01:47
    typescript-bot synchronize #33940
  • 01:29
    amcasey synchronize #15575
  • 01:29
    amcasey synchronize #28460
  • 01:29
    amcasey synchronize #31641
  • 01:28

    amcasey on master

    Add listFilesOnly command-line … Consolidate checks in emitFiles… Add additional properties to sw… and 4 more (compare)

  • 01:28
    amcasey closed #34505
  • 00:47
    DanielRosenwasser edited #34552
  • 00:47
    kitsonk closed #34531
  • 00:42
    DanielRosenwasser synchronize #34552
  • 00:42

    DanielRosenwasser on includeAutomaticOptionalChainCompletions

    Added option 'includeAutomaticO… Add user preference to the prot… Accepted baselines. (compare)

  • 00:24
    andrewbranch review_requested #34553
  • 00:24
    andrewbranch review_requested #34553
  • 00:24
    andrewbranch opened #34553
  • 00:22
    amcasey synchronize #34505
  • 00:17
    DanielRosenwasser synchronize #34552
  • 00:17

    DanielRosenwasser on includeAutomaticOptionalChainCompletions

    Add user preference to the prot… (compare)

  • 00:10
    DanielRosenwasser synchronize #34552
Gareth Jones
@G-Rath
pretty sure that's a bug :grimacing:
AnyhowStep
@AnyhowStep
I'm pretty sure it's not
Gareth Jones
@G-Rath
whys that?
they have the same output
AnyhowStep
@AnyhowStep
(await x) does not give you an expression of type Promise<typeof x>, I'm sure
It's just syntactic sugar
Gareth Jones
@G-Rath
Yeah, that's what I'm questioning
why doesn't it give you an expression of that type? b/c as you say, it's syntactic sugar, so it does give that expression in Node (iirc)
AnyhowStep
@AnyhowStep
If it did return a promise, this would work,
function returnPromise () : Promise<number> {
  return (await 1);
}
Gareth Jones
@G-Rath
which it does
once you add the missing async keyword
AnyhowStep
@AnyhowStep
image.png
Exactly. The async part is the problem here
Gareth Jones
@G-Rath
oh ffs
no wait what
async is in my code
for a second I thought it was I'd just missed async, but nope: async is there
so your example doesn't really relate to mine, as far as I can tell
AnyhowStep
@AnyhowStep

function takesNumberOnly (x : number) {
  console.log(x+1);
}
async function returnPromise ()  {
  const x = await 1;
  takesNumberOnly(x);
  takesNumberOnly(await 1);
}
If (await 1) is an expression of type Promise<number>
Then the second call to takesNumberOnly would not work
Gareth Jones
@G-Rath
Yeah I see. and you're right; this is turning how I figured it would
it's contextual, but too complex to type like that
AnyhowStep
@AnyhowStep
It's sytactic sugar for,
function returnPromise2 ()  {
  Promise.resolve(1)
    .then((x) => {
      takesNumberOnly(x);
      Promise.resolve(1)
        .then((y) => {
          takesNumberOnly(y);
        });
    });
}
Gareth Jones
@G-Rath
yeah yeah
AnyhowStep
@AnyhowStep
gdi gitter highlighting
Gareth Jones
@G-Rath
you need to add ts
im actually slightly disppointed in myself for not putting that together XD
but cheers for the sanity check
AnyhowStep
@AnyhowStep
Sometimes, adding ts doesn't make it any better =x
No problem <3
Gareth Jones
@G-Rath
yeah I know
but so yeah: it's b/c of the await in the inner fn
also ugh ffs my whole fn is redundant XD which is annoying b/c I thought that originally :joy:
AnyhowStep
@AnyhowStep
I didn't even notice till you said it =x
I need to up my code review skillz
Bruce Pascoe
@fatcerberus
(await 1) is expression of type number
It auto-wraps 1 in a promise and then unwraps it
You basically just waited an extra tick for a value you already had :P
AnyhowStep
@AnyhowStep
Kick him down some more :soccer:
Derya Aydede
@Derya
is async/await actually just syntactic sugar?
i was under the impression that it actually is not the exact same as the non-async equivalent

Without await, promises in for loops would be a hassle, especially if each iteration depends on the previous iteration (so no Promise.all())
I think you have to actually use a recursive function for the loop if you can't use await.

Memory is rusty and I'm too lazy to try it out

Derya Aydede
@Derya
yeah you'd have to make some nightmarish construct
thank you based async/await
Bruce Pascoe
@fatcerberus
It’s syntactic sugar as far as the behavior goes, but it being syntax makes it a lot easier to write certain constructs, like AnyhowStep says
The main advantage is you can use the value of a promise at expression-level
Whereas with .then() it’s just one step above callback hell
But other than that it's still just vanilla promise semantics under the hood, right down to the duck-typed .then