Microsoft/TypeScript

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

Open

#57 441 ouverte le 19 févr. 2024

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Domain: flag: isolatedDeclarationsHelp WantedPossible Improvement

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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

Guide contributeur