Skip to content

Aliases are lost when conditionals are applied #61581

Closed as not planned
Closed as not planned

Description

🔎 Search Terms

aliases lost

🕗 Version & Regression Information

Discussion with Mateusz Burzyński (@Andarist):

Anyway, I'm sort of leaving breadcrumbs for myself - sorry for oversharing 😉 I'll dig further later

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAShDOBXANsAPAQQDRQKID4oBeKAbwCgoqoAnCAQwBMB7AO2RCgH1h6BzAFxQARAHkA1sMrU6TNhygA3eskQQhGcgF8oAHzLSqslu049+Q4QDF6AS2RTqtBiYUQaNZjSG5t5cowQAMbI9HRQQWzwwFC28HBIqEIAFIhCiKzirMwA7qwAlMSEiLHwsAgo6PSsIDjVIPj+kazRUABmrMRQmDgEybasYEIJlT14hPrRNAN8hUSEcSOo-YOFAPyxg1CWzJJAA

💻 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

Activity

  1. mikearnaldi commented on Apr 15, 2025

    @mikearnaldi
    ContributorAuthor

    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:

    import { Effect, Unify, Option } from "effect"
    
    type Working = Unify.Unify<Effect.Effect<number> | Effect.Effect<string>>
    //   ^? - Effect.Effect<number | string, never, never>
    
    type NotWorking = Unify.Unify<Option.Option<number> | Option.Option<string>>
    //   ^? - Option.None<number | string> | Option.Some<number | string>
  2. Andarist commented on Apr 15, 2025

    @Andarist
    Contributor

    Fixing this requires making getNarrowedTypeWorker smarter about .origin preservation. It gets lost in this, somewhat unusual, mapType call 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 .origin preservation could kick in.

  3. locked as resolved and limited conversation to collaborators on Dec 3, 2025
  4. RyanCavanaugh commented on Dec 3, 2025

    @RyanCavanaugh
    Member

    Closing language service bugs related to the 6.0 implementation. For more information, see #62827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.0 LS MigrationDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoHelp WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions