As part of a library I write, I want to let the user to pass functions as object's keys:
https://github.com/welldone-software/redux-toolbelt/tree/master/packages/redux-toolbelt#makereducer
For example, in the following, increaseBy
is a function with a custom toString()
that returns a string and decreaseBy.TYPE
is a string.
const reducer = makeReducer({
[increaseBy]: (state, {payload}) => state + payload,
[decreaseBy.TYPE]: (state, {payload}) => state - payload,
}, { defaultState: 100 })
Where increaseBy
is a function that has a custom toString()
that resolves to a string.
JS translates any key to string using toString()
so it works, but my question is:
how safe is it?