Skip to content

Inconsistent boolean literal typesΒ #48363

Closed
@ahejlsberg

Description

@ahejlsberg

πŸ•— Version & Regression Information

This is the behavior in every version I tried.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Box<T> type is invariant in T

type Box<T> = {
    get: () => T,
    set: (value: T) => void
}

declare function box<T>(value: T): Box<T>;

const bn1 = box(0);  // Box<number>
const bn2: Box<number> = box(0);  // Ok

const bb1 = box(false);  // Box<boolean>
const bb2: Box<boolean> = box(false);  // Error, box<false> not assignable to Box<boolean>

πŸ™ Actual behavior

Error on bb2 is surprising and inconsistent with lack of error on bn2.

πŸ™‚ Expected behavior

Expected the box(false) expression to have type Box<boolean> for both bb1 and bb2.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions