Skip to content

type gets widened on declaration emit when inferred in destructuring contextΒ #55439

Open
@h-joo

Description

@h-joo

πŸ”Ž Search Terms

declaration, widened, d.ts, destructuring

πŸ•— Version & Regression Information

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

⏯ Playground Link

https://www.typescriptlang.org/play?jsx=0&module=1&ts=5.1.6#code/GYVwdgxgLglg9mABMOcAUBKAXIg3gTxwEYBfPAKESsQCcBTKEGpXRQxIxE878ugDwAOcGlEQQEAZzGt8iALyIADFwXJUmANxA

πŸ’» Code

function foo(): {y: 1} {
    return { y: 1 }
}

export const { y = 0 } = foo();

πŸ™ Actual behavior

y is number in d.ts files, although the language service says y is 1|0

πŸ™‚ Expected behavior

y is 1|0 in d.ts files.

Additional information about the issue

Without the = 0 assignment y properly becomes type 1 in d.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions