ember-cli-prop-types icon indicating copy to clipboard operation
ember-cli-prop-types copied to clipboard

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

Open cafreeman opened this issue 8 years ago • 0 comments

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

cafreeman avatar Aug 24 '17 17:08 cafreeman