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

String methods properly infering types #16

Open
KajSzy opened this issue Feb 20, 2023 · 1 comment
Open

String methods properly infering types #16

KajSzy opened this issue Feb 20, 2023 · 1 comment

Comments

@KajSzy
Copy link

KajSzy commented Feb 20, 2023

Methods such as toLowerCase and toUpperCase do not properly infer union type that are invoked on.

Typescript Playground Link

There is solution for that, but due to those methods being very ground level it may break things in legacy code.
Thus official typescript is not so keen to change those types.

interface String {
  toLowerCase<T extends string>(this: T): Lowercase<T>;
  toUpperCase<T extends string>(this: T): Uppercase<T>;
}
@gustavoguichard
Copy link

Folks, if you want to go nuts with strongly-typed string functions, check out string-ts library =)

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