You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been an active user of this library across many projects. One problem faced is that the library doesn't retain the literal types. It converts everything to string. For example
typeFruit="orange"|"banana"|"apple"constmyFruit: Fruit="orange";constcapitalCaseFruit=capitalCase(myFruit);// type of capitalCaseFruit = string instead of "Orange" | "Banana" | "Apple";
Why this would be useful?
I have had situations where I want to use the value to index an object. and if the value is string then I have to typecast it explicitly.
Example from above
constobj={priceOrange: 10,priceBanana: 10,priceApple: 10,}obj[`price${capitalCaseFruit}`]=20;// this is not typescript friendly.
of course simple thing to do is typecast it. But it would be great to have inbuilt type inference.
I am willing to contribute to this feature if you guys are open to outside contributions. and eventually, we can add this support to all case types. I am not sure how difficult it would be but I all ears to suggestions. maybe we can have a separate functions for more stricter types? please let me know what you think about this.
The text was updated successfully, but these errors were encountered:
I personally only use this with dynamic data, not typescript typed strings.
I believe that if you want to implement correct typescript type inference, you probably need to re-implement the entire JS logic in pure TS somehow. I'm not sure how that could be possible.
Hey @mesqueeb
I have been an active user of this library across many projects. One problem faced is that the library doesn't retain the literal types. It converts everything to string. For example
Why this would be useful?
I have had situations where I want to use the value to index an object. and if the value is string then I have to typecast it explicitly.
Example from above
of course simple thing to do is typecast it. But it would be great to have inbuilt type inference.
I am willing to contribute to this feature if you guys are open to outside contributions. and eventually, we can add this support to all case types. I am not sure how difficult it would be but I all ears to suggestions. maybe we can have a separate functions for more stricter types? please let me know what you think about this.
The text was updated successfully, but these errors were encountered: