Skip to content

Narrowing on assignment does not remove weak types #26405

Closed
@mattmccutchen

Description

@mattmccutchen

Filing an issue to track the regression from #26143 described in #26143 (comment).

TypeScript Version: master (fe387cc)

Search Terms: narrow assignment weak type assignable comparable

Code

type AOrArrA<T> = T | T[];
const arr: AOrArrA<{x?: "ok"}> = [{ x: "ok" }]; // weak type
arr.push({ x: "ok" });  // Error: Property 'push' does not exist on type 'AOrArrA<{ x?: "ok"; }>'.

Expected behavior: No error.

Actual behavior: Error as indicated above.

Playground Link: N/A, playground is not affected

Related Issues: #26143

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions