[ID-Prep] Type of variable is widened in declaration with !strictNullChecks #57441
Copy link
Copy link
Open
Labels
Domain: flag: isolatedDeclarationsRelated to the --isolatedDeclarations compiler flagRelated to the --isolatedDeclarations compiler flagHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
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
💻 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: flag: isolatedDeclarationsRelated to the --isolatedDeclarations compiler flagRelated to the --isolatedDeclarations compiler flagHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Activity
fatcerberus commentedon Feb 19, 2024
I think this behavior might be connected with automatic literal widening because
Playground
The behavior on
x5_1might seem weird but past input from maintainers has suggested it's intentional.btw your playground link in the OP doesn't seem to work properly - for me it just loads whatever I had last entered into the playground.
[-]Type of variable is widened in declaration with !strictNullChecks[/-][+][ID-Prep] Type of variable is widened in declaration with !strictNullChecks[/+]