Microsoft/TypeScript

[ID-Prep] Type of variable is widened in declaration with !strictNullChecks

Open

#57,441 建立於 2024年2月19日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: flag: isolatedDeclarationsHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.

🔎 Search Terms

const declaration widen

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground Link

💻 Code

declare function f3<T>(a: T, b: T): T;
const x3 = f3("abc", "def");  // "abc" | "def"

🙁 Actual behavior

x3 is emitted as declare const x3: string; in declaration files but it's actually "abc" | "def" in source

🙂 Expected behavior

x3 is emitted as declare const x3: "abc" | "def"

Additional information about the issue

No response

貢獻者指南