Microsoft/TypeScript

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

Aberta

#57.441 aberto em 19 de fev. de 2024

 (1 comentário) (0 reação) (0 responsável)TypeScript (13.395 forks)batch import
Domain: flag: isolatedDeclarationsHelp WantedPossible Improvement

Métricas do repositório

Stars
 (108.860 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

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

Guia do colaborador