Skip to content

Generic with nested object incorrectly constraint suggestions in code completionΒ #61952

Closed as not planned
@Nadelopo

Description

@Nadelopo

πŸ”Ž Search Terms

"suggestions ", "generic", "nested object"

πŸ•— Version & Regression Information

  • This changed between versions 4.9.5 and 5.0.4

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.0.4#code/GYVwdgxgLglg9mABMMAeAKogpgDylsAEwGdEByYOOMxAH3ICMBDAJzID4AKAfQC5EA3gCgAkPmJR+wkSLBMAtln7oA3KJEA3JgBsQSxJlz4ipClRoB+cpWqJ+ZZmzUiAvs6279hvARLXziFZmtvaOZGouAJSCLkJCKJzS4pKC6nKK9jZkADTqHnr2NAD0RYiOdMhUoi65ovn6ZMWlCNoAnpVwQlFAA

πŸ’» Code

function fn<T extends 'foo' | 'bar'>(_: {
  test: {
    name: T
    value: T extends 'foo' ? 'foo' : 'bar'
  }
  value: T extends 'foo' ? 'foo' : 'bar'
}) {}

fn({
  test: {
    name: 'foo',
    value: '' // bar | foo
  },

  value: '' // only foo
})

πŸ™ Actual behavior

suggests 'bar' and 'foo' for nested object

πŸ™‚ Expected behavior

should suggest only 'bar' for nested object

Additional information about the issue

Generic type constraints do not properly narrow suggestions in nested object properties

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions