Skip to content

Type guard not working in nested conditional typesΒ #45651

@07akioni

Description

@07akioni

Bug Report

πŸ”Ž Search Terms

type guard, nested conditional types

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • βœ… This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.4.2#code/C4TwDgpgBAggJnACgJwPZgCqoPICMBWEAxsADx75QQAewEAdnAM5SoHHAA0UK6VtDZlCbBkAS3oBzAHxQAvDzRh+dRiwDWEEKgBmUCgCgoUAPz6CAbV5gAuisEsArvXX1UAd3oWbR46agWAHTBFFZKNj5+UABcUPQQAG4QyL6x8UnIQA

Playground link with relevant code

πŸ’» Code

type AddPropToObject<Obj extends object, Prop extends string> = Prop extends keyof Obj
  ? Obj[Prop] extends unknown[]
    ? [...Obj[Prop]]
    : never
  : never

πŸ™ Actual behavior

Obj[Prop] is not viewed as an array.

image

πŸ™‚ Expected behavior

Obj[Prop] should be viewed as an array.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions