Skip to content

Union in template literal simplifying unexpectedlyΒ #58340

Closed as not planned
Closed as not planned
@rj-lee

Description

@rj-lee

πŸ”Ž Search Terms

template literal union distributive conditional type

πŸ•— Version & Regression Information

5.4.5 and Nightly

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.4.5#code/C4TwDgpgBAYg9nAclAvFABgMwQEgN4DkAjAAwkFQA+UAFOvgHYCuAtgEYQBOAvulAGRQ83AJS8A3ACgA9NKihIsBMjRZceenmbsuvAUO68ZciAA9IAY2AQAJqigAibHFIkHVDM-ybtHHn0FhXiA

πŸ’» Code

type FooN = `foo${'100' | (`${number}` & {})}`;
// type FooN = `foo${`${number}` & {}}`
// expected = "foo100" | `foo${`${number}` & {}}`

πŸ™ Actual behavior

'100' and `${number}` & {} are being simplified to `${number}` & {}. FooN does not have autocomplete for 'foo100'

πŸ™‚ Expected behavior

FooN should be of type "foo100" | `foo${`${number}` & {}} and provide autocomplete for foo100 while allowing foo101 or any other number

Additional information about the issue

No response

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