Skip to content

Regression with await type extraction in strict mode #32752

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

Closed
ulrichb opened this issue Aug 7, 2019 · 1 comment · Fixed by #32919
Closed

Regression with await type extraction in strict mode #32752

ulrichb opened this issue Aug 7, 2019 · 1 comment · Fixed by #32919
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ulrichb
Copy link

ulrichb commented Aug 7, 2019

TypeScript Version: 3.6.0-dev.20190807 (worked up to 3.6.0-dev.20190804)

Search Terms: await type promise

Code

const containsPromises: unique symbol = Symbol();

type DeepPromised<T> =
    { [containsPromises]?: true } &
    {
        [TKey in keyof T]: T[TKey] | DeepPromised<T[TKey]> | Promise<DeepPromised<T[TKey]>>
    };

async function fun<T>(deepPromised: DeepPromised<T>) {

    const deepPromisedWithIndexer:
        DeepPromised<{ [name: string]: {} | null | undefined }> = deepPromised;

    for (const value of Object.values(deepPromisedWithIndexer)) {

        const awaitedValue = await value;

        if (awaitedValue)
            await fun(awaitedValue);
    }
}

(Compile with --strict!)

Expected behavior:
No compile error as in TS 3.5.3.

Actual behavior:

TypeScriptIssueNext.ts:21:23 - error TS2345: Argument of type '{} | ({ [containsPromises]?: true | undefined; } & {})' is not assignable to parameter of type 'DeepPromised<{ [containsPromises]?: undefined; }>'.
  Types of property '[containsPromises]' are incompatible.
    Type 'true | undefined' is not assignable to type '(true & Promise<never>) | undefined'.
      Type 'true' is not assignable to type '(true & Promise<never>) | undefined'.

21             await fun(awaitedValue);
                         ~~~~~~~~~~~~

Playground Link: Here
BTW: Please update the libs in the playground, Object.values() (ES2017) isn't available.

Related Issues: -

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.1 milestone Aug 7, 2019
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 7, 2019
@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label Aug 15, 2019
@ahejlsberg
Copy link
Member

Simpler repro:

type Deep<T> = { [K in keyof T]: T[K] | Deep<T[K]> };

declare function foo<T>(dp: Deep<T>): T;
declare let xx: { a: string | undefined };

foo(xx);  // Error

@ahejlsberg ahejlsberg added Fixed A PR has been merged for this issue and removed Fix Available A PR has been opened for this issue labels Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants