Skip to content

Reordering variable declarations of Promise<any> and Promise<unknown> changes behaviorΒ #52100

@dragomirtitian

Description

@dragomirtitian

Bug Report

πŸ”Ž Search Terms

Promise<any> Promise<unknown> instantiation order

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Reorder these two
declare let u: Promise<unknown>
declare let a: Promise<any>

// Assigned an expression that is Promise<any> | Promise<unknown>
// but that will undergo subtype reduction
// The type of union depends on whether a or u was declared first
let union = Math.random() > 0.5
    ? Promise.reject<any>()
    : Promise.reject<unknown>();

union.then(v => v.toString());

πŸ™ Actual behavior

Reordering the unrelated variables u and a will cause the type of union to change between Promise<unknown> and Promise<any> (both in declarations and in the type of v, although tooltips still show union as Promise<any>)

πŸ™‚ Expected behavior

The type of union should not be impacted

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions