Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsc 3.6.3: Promise.all breaks with some union type #33562

Closed
paul-marechal opened this issue Sep 23, 2019 · 2 comments · Fixed by #45350
Closed

tsc 3.6.3: Promise.all breaks with some union type #33562

paul-marechal opened this issue Sep 23, 2019 · 2 comments · Fixed by #45350
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@paul-marechal
Copy link

paul-marechal commented Sep 23, 2019

TypeScript Version: 3.6.3

Search Terms: promise all

Code

type MaybePromise<T> = T | Promise<T> | PromiseLike<T>

function MaybePromise<T>(value: T): MaybePromise<T> {
    return Promise.resolve(value)
}

async function main() {
    let aaa: number
    let bbb: string
    [
        aaa,
        bbb,
    ] = await Promise.all([
        MaybePromise(1),
        MaybePromise('2'),
        MaybePromise(true),
    ])
}

tsconfig:

{
  "compilerOptions": {
    "strict": true,
    "target": "es5",
    "module": "commonjs",
    "lib": [
      "es6"
    ]
  }

Expected behavior:

Code should compile without errors.

Actual behavior:

Error:

test.ts:11:9 - error TS2322: Type 'number | Promise<1>' is not assignable to type 'number'.
  Type 'Promise<1>' is not assignable to type 'number'.
test.ts:12:9 - error TS2322: Type 'string | Promise<"2">' is not assignable to type 'string'.
  Type 'Promise<"2">' is not assignable to type 'string'.

Code compiles well with 3.5.3, but not 3.6.3 nor 3.7.0-dev.20190922.

Playground Link:

Weirdly enough, on the playground the return value of Promise.all is not a tuple but a list.

https://www.typescriptlang.org/play/#code/C4TwDgpgBAsghiARhACgJwPYFsCWBnCAHgBUA+KAXimKgB8p1t8iy6HNcCAZHAaxdIAoQQDMArgDsAxsBwYJsBMkacBACgBucADZiIALmoBKQ-CSoOzEuQDegqA6hoIwMWgUrmAOmd4M2jQhNHT0jQQBfYTg8EGkocWlZeSgsOBwJNSMoO0cobRcoOCLDCTEsZDR7R3zgKER6wzxgNHSAcyqHAG0O3MKigBoe3PrEQdyAXUpCgHc02s8CLx1tNW7exzNlSwI1AEYjMfXFcwWggHIAJjODoY2lCyYd5tDDh3GwyKA

Related Issues:

@paul-marechal
Copy link
Author

Encountered this issue while updating tsc, will stay on 3.5.3 until this is resolved :)

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 25, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.0 milestone Sep 25, 2019
@sandersn
Copy link
Member

sandersn commented Oct 1, 2019

#33559 is only in 3.7, so is probably not related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
6 participants