ts-reset
ts-reset copied to clipboard
String methods properly infering types
Methods such as toLowerCase
and toUpperCase
do not properly infer union type that are invoked on.
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>;
}
Folks, if you want to go nuts with strongly-typed string functions, check out string-ts
library =)
I'm coming back to this issues list a year later and I want to define some reasonable rules for what ts-reset should and shouldn't accept. I think string methods inferring proper types is not part of that.
My thinking is that tight string inference should be something that you opt-in to at the call site. @gustavoguichard's library string-ts
is a great example of this.
My reasoning is that you don't care about this behavior MUCH more often than you do. Most of the time, you just want to deal in string
inputs and string
outputs. Adding this extra overhead to the TS compiler doesn't seem right to me.
Plus - I want to keep ts-reset small. In that spirit, I won't be adding this to the library.
Thanks for the issue!