-
-
Notifications
You must be signed in to change notification settings - Fork 146
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
How to negate multiple numbers at once? #106
Comments
Hey @kripod this is the right way to do it! It's my fault, there is a bug 🐛. |
The fix will be out in minutes. Sorry about this :) Here's another way to write it: const obj = {
0 : 0,
'1px': '1px',
1 : '0.25rem',
2 : '0.5rem',
}
type Nbrs = Number.Negate<Number.NumberOf<keyof typeof obj & number>> |
Fantastic, thank you! That was very quick. |
Is it possible to negate the |
Pleasure! No it is not possible is pure ts, but we could build a map for pixels to enable this. If you look at how I've built operations on If you are OK having a limitation that is from '-40px' to '40px'. This is the limitation we have for |
Wonderful 😲 |
Let me know if you need help to integrate such a feature, I didn't actually go very much in detail. Don't hesitate to contact me via gitter or open another issue. I speculated many times that I should give the possibility to pass custom number maps (like pixels, or percents). I could implement this if you want. From there on, any custom map could be passed. |
I'd highly appreciate if you could implement the ability to use custom maps, so project maintainers wouldn't have to copy a lot of boilerplate code, but would have a reusable, tested solution available. By the way, I would use this for a new CSS-in-JS library with customizability, type-safety and performance in mind. |
Yo @kripod the new mapping system is on the way. You can now use pixel maps and perform math operations on it. It enabled considerable optimizations as well as more flexibility. So you can get started with pixel math! If you need an example, please take a look at the tests https://github.com/pirix-gh/ts-toolbelt/blob/master/tst/Number.ts I'll take a look to optimize cc @tonivj5 |
Awesome job, thank you! Unfortunately, I need to negate values from 0–64, so I opted for a custom solution until a more optimized version is available. |
You can use it now, it's been fixed. New limits are from import {N, M} from 'ts-toolbelt'
type test0 = N.Negate<'100px', 's', M.Iteration.Pixel> |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
🤔 Question
Describe your question
I am trying to negate the keys of an object type. Currently, I'm trying with the following approach:
Unfortunately,
newObj
is shown as astring
instead of'0' | '-1' | '-2'
.Search tags, topics
negate, multiple, inference
The text was updated successfully, but these errors were encountered: