Skip to content

Template types don't resolve in conditional typesΒ #59749

Closed as not planned
Closed as not planned
@benthayer

Description

@benthayer

πŸ”Ž Search Terms

conditional types, resolve, template

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types, templates

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240825#code/C4TwDgpgBAglC8UDeAoKUCGAuKBnYATgJYB2A5igL4oqiRQBCCyaUARjvseVTXdAFkQAFXAQAPMKgQAHsAgkAJrlhQAPowB8zFFNnylKuAH4oAcgxmoOM2zM0AZgFcSAY2BEA9iSgPPnyWk5BWVYTQAKAEocADdPIkUWdFdvfCgZHCFRSEltRAt7dBkqIA

πŸ’» Code

type A = {
  a: string
}

type B = {
  b: string
}

type MyType<T extends A | B> = 
T extends A ? 'a' : 'b'

function foo<T extends A>(): void {
  const x: MyType<T> = 'a'
  x
}

πŸ™ Actual behavior

Type "a" is not assignable to MyType

πŸ™‚ Expected behavior

Type "a" is assignable to MyType

Additional information about the issue

This additional snippet works as expected:

const x: MyType<A1> = 'a'
x

type A1 = {
  a: string
  a1: string
}

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