Skip to content

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

@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 TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions