Skip to content

Type assertion does not creates a type union anymore  #54883

Closed as not planned
Closed as not planned
@drtex0

Description

@drtex0

Bug Report

Since version 5.1.X I am facing this issue with type assertion. In version 5.0.X the type resolves with an Union of the original type & the assertion type. However in 5.1.X there is only the original type left

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 5.0.1 and 5.1.3
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type assertion
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

import { mapValues } from 'lodash';

type Dinero  = {
  mul: () => number
}

const isDinero = (obj: unknown): obj is Dinero => 
  typeof obj === "object" && obj !== null && Object.hasOwn(obj, "mul")

const transformValues = <Contract extends object>(contract : Contract)  => {
   mapValues(contract, (value, key) => {
      if(isDinero(value)) {
        //  value -> Contract[keyof Contract] in TS 5.1.X
        // value: Contract[keyof Contract] & Dinero in TS 5.0.X
        value.mul() 
        
      }

    })

}

🙁 Actual behavior

The type value is Contract[keyof Contract

🙂 Expected behavior

The type value to be at least Contract[keyof Contract] & Dinero

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions