Skip to content
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

Symbols will not work with normal String concat #106

Closed
wants to merge 1 commit into from

Conversation

tbranyen
Copy link

An example pulled from the Chrome Devtools Console:

const INCREMENT_COUNTER = Symbol('INCREMENT_COUNTER');
INCREMENT_COUNTER + "Hello"
VM222:2 Uncaught TypeError: Cannot convert a Symbol value to a string(…)

The fix is simple, coerce to a String by invoking the constructor around it.

I am surprised this wasn't already added since I can see Symbol(...) working correctly in the README screenshot.

An example pulled from the Chrome Devtools Console:

```
const INCREMENT_COUNTER = Symbol('INCREMENT_COUNTER');
INCREMENT_COUNTER + "Hello"
VM222:2 Uncaught TypeError: Cannot convert a Symbol value to a string(…)
```

The fix is simple, coerce to a String by invoking the constructor around
it.
@imevro
Copy link
Collaborator

imevro commented Dec 16, 2015

Logger has actionTransformer option for that things ✊

import createLogger from 'redux-logger';

const logger = createLogger({
  actionTransformer: (action) => ({
    ...action,
    type: String(action.type),
  });
});

@imevro imevro closed this Dec 16, 2015
@tbranyen
Copy link
Author

Rock on, thanks!

@youfoundron
Copy link

I find this to be a slight improvement as it eliminates the redundancy of seeing 'Symbol(<type string>)' wrapping your type string every time it is logged in the console:

import { createLogger } from 'redux-logger'

const typeRegEx = /Symbol\((.*?)\)/
const logger = createLogger({
  actionTransformer: action => ({
    ...action,
    type: String(action.type).match(typeRegEx)[1]
  })
})

@tbranyen tbranyen deleted the fix-symbol-support branch May 8, 2017 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants