Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:41
    felixge edited #35124
  • 10:41
    felixge edited #35124
  • 10:39
    felixge opened #35124
  • 10:33
    Richiban edited #35086
  • 08:24
    sheonhan opened #35123
  • 07:58
    DanielRosenwasser labeled #4035
  • 07:58
    ajafff edited #35090
  • 07:57
    ajafff synchronize #35090
  • 07:57
    DanielRosenwasser demilestoned #4035
  • 07:56
    DanielRosenwasser unlabeled #4035
  • 07:56
    DanielRosenwasser unassigned #4035
  • 06:43
    screendriver opened #35122
  • 04:28
    typescript-bot synchronize #35117
  • 02:29
    typescript-bot synchronize #35117
  • 02:10
    DanielRosenwasser labeled #35121
  • 02:10
    DanielRosenwasser labeled #35120
  • 02:10
    DanielRosenwasser labeled #35115
  • 02:10
    DanielRosenwasser labeled #35114
  • 02:10
    DanielRosenwasser labeled #35113
  • 02:09
    DanielRosenwasser edited #35121
Bruce Pascoe
@fatcerberus
Never found a good solution :(
Bruce Pascoe
@fatcerberus
If it’s generic though, what about F extends Function?
AnyhowStep
@AnyhowStep
No good, can't use the infer R syntax if you're using extends Function
Also, my concrete F will still end up having never in the param and will break ReturnType<> =x
Even if I'm using Function as the top type for functions
Keith Layne
@keithlayne
IIRC all function has is a name member.
raghanag
@raghanag
hi all, if the typescript class constructor has too many lines, are we going to stub all of it when we are writing unit tests
AnyhowStep
@AnyhowStep
What does that question even mean
Bruce Pascoe
@fatcerberus
@keithlayne Function doesn’t guarantee that it’s callable?
Because that’s kind of sucky if it doesn’t
Keith Layne
@keithlayne
I must have seen an augmentation instead of the actual definition, my bad
Gareth Jones
@G-Rath
ok want to see something interesting?
interface Mx {
  v: string;
}

const promiseTuple = async <T1, T2>(t1: T1, t2: Promise<T2>): Promise<[T1, T2]> =>
  [t1, await t2];

const doThings = async (): Promise<Array<[string, Mx[]]>> => Promise.all([
  promiseTuple('hello', Promise.resolve([{ v: 'sunshine' }])),
  promiseTuple('world', await [{ v: 'peace' }])
]);

doThings().then(r => r.forEach(console.log));
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