Skip to content

Regression with await type extraction in strict mode #32752

Closed
@ulrichb

Description

@ulrichb

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: -

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions