Skip to content

Why can't we use the toLowerCase() and toUpperCase() string methods to solve the Lowercase and Uppercase utilities? #50970

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

Closed
YadBro opened this issue Sep 27, 2022 · 3 comments

Comments

@YadBro
Copy link

YadBro commented Sep 27, 2022

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is a crash

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface ITodo {
    activity: Lowercase<string>, // (Error) Type 'string' is not assignable to type 'Lowercase<string>'.
    description: Uppercase<string>, // (Error) Type 'string' is not assignable to type 'Uppercase<string>'.
}

const todo: ITodo = {
    activity: 'Fishing'.toLowerCase(),
    description: 'Fishing with your mom'.toUpperCase(),
}
console.log(todo);
@MartinJohns
Copy link
Contributor

Because both toLowerCase() and toUpperCase() return a string, not Lowercase<string> or Uppercase<string>. Changing this would be a breaking change. The issue for this is still open: #44268

@YadBro
Copy link
Author

YadBro commented Sep 27, 2022

I'm still confused, I think it should work. Well don't think about it. Thanks for the explanation. I will close this issue thank you.

@YadBro YadBro closed this as completed Sep 27, 2022
@fatcerberus
Copy link

I'm still confused, I think it should work.

.toLowerCase() is just another method that returns a string, like any other; the compiler doesn’t have any context to know this particular string is compatible with Lowercase<string>.

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

3 participants