Repository navigation
Aliases are lost when conditionals are applied #61581
Copy link
Copy link
Closed as not planned
Labels
7.0 LS MigrationDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoHelp 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
🔎 Search Terms
aliases lost
🕗 Version & Regression Information
Discussion with Mateusz Burzyński (@Andarist):
- TypeFormatFlags.InTypeAlias is at fault here, it's rather hard to track its exact conceptual purpose. And it has been there forever - I found commits with it from 9 years ago
- I briefly thought this might be related to ur issue: Type alias printing regressed in TypeScript 4.2.2 #43031
but now I'm pretty sure it isn't - but it's also a somewhat funny issue because it complains about an alias for a union being lost and it was broken by a PR that... introduces improved union/intersection aliasing 😄 Preserve type aliases for union and intersection types #42149 , there was also a quick follow up to this PR that feels slightly related: Support re-aliasing of type alias instantiations #42284
Anyway, I'm sort of leaving breadcrumbs for myself - sorry for oversharing 😉 I'll dig further later
⏯ Playground Link
💻 Code
type Result<A, E> = {
readonly _tag: "Ok"
readonly value: A
} | {
readonly _tag: "Fail"
readonly error: E
}
declare const isResult: (u: unknown) => u is Result<any, any>
const fn = <A, E>(inp: Result<A, E> | string) => isResult(inp) ? inp : "ok"🙁 Actual behavior
const fn: <A, E>(inp: Result<A, E> | string) => {
readonly _tag: "Ok";
readonly value: A;
} | {
readonly _tag: "Fail";
readonly error: E;
} | "ok"🙂 Expected behavior
const fn: <A, E>(inp: Result<A, E> | string) => Result<A, E> | "ok"Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
7.0 LS MigrationDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoHelp 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
mikearnaldi commentedon Apr 15, 2025
Correction, breadcrumbs from Mateusz Burzyński (@Andarist) appears to be unrelated, they instead relate to the following code where it is only the printer at fault, instead in this case aliases are completely lost:
Andarist commentedon Apr 15, 2025
Fixing this requires making
getNarrowedTypeWorkersmarter about.originpreservation. It gets lost in this, somewhat unusual,mapTypecall here:https://github.dev/microsoft/TypeScript/blob/4dc677b292354f4b9162452b2e00f4d7dd118221/src/compiler/checker.ts#L29346-L29365
Maybe some special path has to be introduced to handle this but maybe it's possible to restructure this somehow so the existing code paths responsible for
.originpreservation could kick in.RyanCavanaugh commentedon Dec 3, 2025
Closing language service bugs related to the 6.0 implementation. For more information, see #62827