Replies: 11 comments
-
Hey @kripod this is the right way to do it! It's my fault, there is a bug 🐛. |
Beta Was this translation helpful? Give feedback.
-
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>> |
Beta Was this translation helpful? Give feedback.
-
Fantastic, thank you! That was very quick. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to negate the |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Wonderful 😲 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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> |
Beta Was this translation helpful? Give feedback.
-
🤔 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
Beta Was this translation helpful? Give feedback.
All reactions