Skip to content

Assertion function & Type guards for Record types broken on 5.0 ย #53379

@JeanMeche

Description

@JeanMeche

๐Ÿ”Ž Search Terms

  • asserts
  • assertion function
  • type guard
  • record

๐Ÿ•— Version & Regression Information

Worked on 4.9, broken since 5.0

Probably introduced by #52984

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

declare function isObject(o: unknown): o is Record<string, any>

declare function assertObject(o: unknown): asserts o is Record<string, any>  

let value: {} = null!;
if(isObject(value)) {
    value.anything // error since 5.0.2
}

assertObject(value)

value.anything // error since 5.0.2

๐Ÿ™ Actual behavior

Property 'anything' does not exist on type '{}'.(2339)

๐Ÿ™‚ Expected behavior

No error, narrowing / assertion should work fine.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions