Skip to content

intersection type between two template literal type will never be 'never' type #60446

Description

@anatawa12

🔎 Search Terms

intersection template type never

🕗 Version & Regression Information

  • I was unable to test this on prior versions than 4.5 because // ^? does not work on typescript playground

I think this is bug since template literal type is introduced in 4.1.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241106#code/GYVwdgxgLglg9mABAQzATwBQEoBcL2IDeiUAFgE5wDuiYIANvQNyIC+AUOxAgM5QkBTPgFY8AAwC2MZCDIB6ACSE+5GGADmrORFICIAazGIAZIjFKVazXNgSB9NQKMBefJixN2cuYl++AegD8Xj5+ZDA8iDykcAwAJogARgK0AgBuAuRJsohxcEK0cFDsQA

💻 Code

functionany(): any{thrownull;}consttest5: `miauth/${string}/check` & `${string}/timeline` =any();// ^?// this should be never but does not

🙁 Actual behavior

`miauth/${string}/check` & `${string}/timeline` will remain `miauth/${string}/check` & `${string}/timeline`

not coming never would cause problem with Indexed Access Types

functionany(): any{thrownull;}typeEndpoints={'test/timeline': 0,'test2/timeline': 0,'other endpoint': 2,[ep: `miauth/${string}/check`]: 1,// no error at test2 if comment}typeTimelineEndpoints=keyofEndpoints& `${string}/timeline`;consttest2: Endpoints[TimelineEndpoints]=any();consttest3: 0=test2;// This assignment should not have type errors,// but because `miauth/${string}/check` & `${string}/timeline` is not never,// test2 become 0|1 so we cannot assign test2 to test3.

playground

🙂 Expected behavior

`miauth/${string}/check` & `${string}/timeline` should become never and Endpoints[TimelineEndpoints] in snippet above should become 0

Additional information about the issue

Of course, we cannot assign variable typed `miauth/${string}/check` to `${string}/timeline` and vice versa.

functionany(): any{thrownull;}consttest0: `miauth/${string}/check` =any();consttest1: `${string}/timeline` =test0;// error here, as expected

playground

Real world case: misskey-dev/misskey#14885 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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