Skip to content

Type alias printing regressed in TypeScript 4.2.2 #43031

Closed as not planned
Closed as not planned

Description

@AlCalzone

Bug Report

🔎 Search Terms

preserve type alias

🕗 Version & Regression Information

  • This changed between versions 4.1.5 and 4.2.2

⏯ Playground Link

Playground link with relevant code

💻 Code

type Brand<K, T> = K & { __brand: T };

type BrandedUnknown<T> = Brand<"unknown", T>;
type Maybe<T> = T | BrandedUnknown<T>;

class Foo {
    public readonly maybe: Maybe<boolean> | undefined;
}

declare const foo: Foo;
const test = {
    prop: foo.maybe || false,
    // 4.1.5 (good): Maybe<boolean>
    // 4.2.2  (bad): boolean | BrandedUnknown<boolean> 
}

🙁 Actual behavior

test.prop has type boolean | BrandedUnknown<boolean> which lost the connection to Maybe<boolean>

🙂 Expected behavior

test.prop should have type Maybe<boolean> like in previous versions.

Activity

  1. AlCalzone commented on Mar 3, 2021

    @AlCalzone
    ContributorAuthor

    Simplified repro without the class - seems it has to do with || vs. ??:

    type Brand<K, T> = K & { __brand: T };
    
    type BrandedUnknown<T> = Brand<"unknown", T>;
    type Maybe<T> = T | BrandedUnknown<T>;
    
    // got:      boolean | BrandedUnknown<boolean>
    // expected: Maybe<boolean>
    const test1 = (undefined as Maybe<boolean> | undefined) || false;
    
    // got: Maybe<boolean>
    const test2 = (undefined as Maybe<boolean> | undefined) ?? false;

    Playground

  2. added
    Domain: LS: Type Display
    on Oct 16, 2025
  3. RyanCavanaugh commented on Dec 3, 2025

    @RyanCavanaugh
    Member

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

  4. locked as resolved and limited conversation to collaborators on Dec 3, 2025
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 MigrationBugDomain: LS: Type Display

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions