Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.

Use Object cast for safe property access #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maxnordlund
Copy link

@maxnordlund maxnordlund commented Nov 3, 2018

Without these you'll get one of these errors TypeError: Cannot read property 'constructor' of undefined or TypeError: Cannot read property 'constructor' of null.

Without these you'll get this error:
`TypeError: Cannot read property 'constructor' of undefined`
@maxbrunsfeld
Copy link
Contributor

Oh thanks for catching that; that's a really bad error message.

Regarding the implementation, it seems a bit more straightforward to just explicitly check for value is null (or undefined)

if (value == null) {
  throw new Error('Missing rule value');
}

switch (value.constructor) {
  // ...
}

Thoughts?

@maxnordlund
Copy link
Author

Yes, that's a good idea. But I didn't want to change anything, especially not throw new errors.

But if you think it's better I can change it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants