4 ms·
Just a tip to make that syntax a bit less ugly[0] Using babel / typescript `a.b = c` becomes `Object.assign({}, a, { b = c })` can be written as `{...a, b: c
by benjaminjackman 9y ago
Just a tip to make that syntax a bit less ugly[0] Using babel / typescript
`a.b = c` becomes `Object.assign({}, a, { b = c })`
can be written as
`{...a, b: c}`
(this desugars in typescript to)
`Object.assign({}, a, { b: c });` [1]
(note also you had a minor typo there with equal sign {b=c} should be a colon, I feel like I make that mistake multiple times per day when writing typescript / javascript, having two different assignment operator characters in the language is not good imho. i'd prefer if it was all just `=`, that will never change at this point though. )
For your seconds example,
`store.dispatch({type: METHOD, data})`
perhaps the Proxy object[2] (which allows for delegation, method_missing like functionality) could be used to turn the calls back into store.method(data)
0: Beauty is in the eye of the beholder as they say.
1: https://www.typescriptlang.org/play/#src=const%20a%20%3D%20%7B%20b%3A%201%20%7D%0D%0Aconst%20c%20%3D%202%0D%0A%0D%0Aconst%20x%20%3D%20%7B%20...a%2C%20b%3A%20c%20%7D https://www.typescriptlang.org/play/#src=const%20a%20%3D%20%...
2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- jtmarmon 9y agojust to be pedantic: object rest spread[1] is a JS feature implemented by babel, not really a typescript feature [1] https://babeljs.io/docs/plugins/transform-object-rest-spread/ https://babeljs.io/docs/plugins/transform-object-rest-spread...
- deleted 9y ago[deleted]
- mercer 9y agoJust to clarify (and pile on more pedantry?): it's a JS feature that is also implemented by TS, so while you're correct that it's not a TS feature, it's also not particular to Babel. In fact, sometimes I like to use TS because it allows me to skip the Babel part of the process entirely.
- deleted 9y ago[deleted]
- noncoml 9y ago> Just a tip to make that syntax a bit less ugly[0] Using babel / typescript > `a.b = c` becomes `Object.assign({}, a, { b = c })` > can be written as > `{...a, b: c}` That's very true, but it still not expressively correct in my eyes.
- shadow_banned 9y agoThen don't use it