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

Bug: string is not a string #60764

Open
HansBrende opened this issue Dec 14, 2024 · 3 comments
Open

Bug: string is not a string #60764

HansBrende opened this issue Dec 14, 2024 · 3 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@HansBrende
Copy link

πŸ”Ž Search Terms

string extends template bug wrong error conditional

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.2#code/FAFwngDgpgBAcgexgXhgbQGYEMA2BnKAXWFElgEk8BBAZRACcBLAOwHMAeGgPhRhpigAPEFGYATPDAAGAEgDeLDFHowA+gF8pMAPwwGAV1gAuGNnxQA3CXDQ+DFq0q17bdgBUBw0RJh4XrHlQ0JzomV1k5N00uQk8RcUlEHVNcAhgTAygSAGMEZj9fAAsEfRwxKhwAdywwPAAhKDd6QxNQhxD-dgByPC7AvWbLIA

πŸ’» Code

type No = [false]

type IsAString<S> = S extends `${infer _}` ? true : false;

type StringIsAString<T extends string> = [IsAString<`${T}`>] extends No ? false : true

const shouldAlwaysBeTrue: StringIsAString<'s'> = true;

πŸ™ Actual behavior

shouldAlwaysBeTrue reports the following error:

Type 'true' is not assignable to type 'false'.(2322)

πŸ™‚ Expected behavior

No error

Additional information about the issue

This is the most minimal reproduction of the issue I could come up with after whittling it down from a much more complicated scenario.

Interestingly enough, if I change almost anything about it, the issue goes away. For example, if I replace No with [false], issue goes away. If I take out one of the templates, issue goes away. Etc.

@MartinJohns
Copy link
Contributor

Possibly a duplicate of #57650.

@HansBrende
Copy link
Author

I read through that other issue and I don't see how it could be a duplicate, as I'm not sure how a so-called "permissive instantiation" of No could be anything other than [false]. But it's also possible that it is the same issue and I'm too stupid to understand the connection πŸ˜†

@HansBrende
Copy link
Author

Addendum: just realized I can dispense with the No type altogether for a slightly more minimal repro as follows:

type IsAString<S> = S extends `${infer _}` ? true : false;
type StringIsAString<T extends string> = {result: IsAString<`${T}`>} extends {result: false} ? false : true
const shouldAlwaysBeTrue: StringIsAString<'s'> = true;

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Dec 16, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants