Is it possible to catch typos, as in the example case switch example?
The preferred way is that eslinter reports a warning / error. Currently, adding toString() to const can be used to raise a TypeError at runtime if undefined.
actionTypes.js
export const UPDATE_REQUEST = 'UPDATE_REQUEST';
reducer.js
import * as types from '../constants/actionTypes'; export default function pouchdbReducer(state = {}, action) { switch (action.type) { case types.UPDDATE_REQUEST: // there is a typo above and it evaluates to `undefined` // this code would never be reached - how to make it an error return Object.assign({}, state, {updated: true}); default: return state; } }
UPDATE:
As @ nikc.org answered, eslint-plugin-import with namespace can be used to sort through such errors.
Here is a small repository with configuration and demo:
https://github.com/bmihelac/test-js-import-undefined/tree/eslint-plugin-import
The relevant part of eslint configuration:
"plugins": ["import"], "rules": { "import/namespace": [2],
source share