Skip to content

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

Closed
@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