Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type alias printing regressed in TypeScript 4.2.2 #43031

Open
AlCalzone opened this issue Mar 1, 2021 · 1 comment Β· May be fixed by #61362
Open

Type alias printing regressed in TypeScript 4.2.2 #43031

AlCalzone opened this issue Mar 1, 2021 · 1 comment Β· May be fixed by #61362
Labels
Bug A bug in TypeScript
Milestone

Comments

@AlCalzone
Copy link
Contributor

AlCalzone commented Mar 1, 2021

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.

@AlCalzone
Copy link
Contributor Author

AlCalzone commented Mar 3, 2021

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

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 9, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants