Skip to content

Is it possible to use PropTypes.shape with an Ember Object? #13

Description

@cafreeman

Hello!

I was wondering if there's any to use PropTypes.shape with an EmberObject?

I know you can use instanceOf to check that a thing is an EmberObject, but I'd also like to still assert against its internal properties as well.

Summary

When I use shape to describe an Ember.Object, I get failed prop types for the individual keys, even though I can verify the keys are correct.

Example

For example, let's say I have an Ember model:

export default DS.Model.extend({
  type: DS.attr('string'),
  items: DS.attr(),
});

I'd like to check that using prop-types, like so:

export default P.shape({
  type: P.oneOf([
    'conversation',
    'route'
  ]).isRequired,

  items: P.oneOf([
    P.arrayOf(Message),
    P.string
  ]).isRequired,
});

However, when I try to use this type in a component by passing in something like:

{
  type: "conversation",
  ...
}

I see the following failed prop-type:

image

Environment Information

Here's my setup:

  • OS: masOS El Capitan
  • Ember + Ember CLI Version: Ember 2.15
  • Node/NPM Version: Node 7, npm 3
  • Browser: Chrome, latest

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions