Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency with Template Literal Types and Conditional Types #57983

Closed
13OnTheCode opened this issue Mar 28, 2024 · 1 comment
Closed

Inconsistency with Template Literal Types and Conditional Types #57983

13OnTheCode opened this issue Mar 28, 2024 · 1 comment

Comments

@13OnTheCode
Copy link

🔎 Search Terms

"Template Literal Types", "Conditional Types", "${number}"

🕗 Version & Regression Information

5.4.3

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAKhDOwA8MoQB7AgOwCbykQCcBLbAcwD4oBeWNTHfKAJQgGMB7I3FAGigBXbAGtsnAO7ZqAfijAig6AC4oAMwCGAG3gQAUHtCRYABgCMtWAmQADACQBvbIIC2AIwhEAvjcp6A9P5QwQB6MgZG0DAmAEyWcIhI9g5uJORkwD5+gcFQYRHgUSYAzPHWSY7EZORZAUGh4UA

💻 Code

type Test<T extends string> = T extends Record<T, unknown> ? true : false

type T01 = Test<`${number}`> // true

type T02 = Test<`${bigint}`> // false

type T03 = Test<`${string}`> // false

🙁 Actual behavior

inconsistent behavior

🙂 Expected behavior

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Mar 28, 2024

I’m struggling to understand what you’re trying to demonstrate. Surely, in general, Test<T> should depend on T, so why would it be “inconsistent” for different inputs to lead to different outputs?

Why would one expect a template literal to be usable as a key to itself? When do you write str[str] and expect that to make sense? Strings have a numeric index signature but not a string index signature or a “bigint index signature” so things look reasonable to me.

I think you should strongly consider explaining the expected/actual behavior instead of assuming it’s obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants