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

Prototypical Record Types? #141

Closed
JAForbes opened this issue Apr 28, 2017 · 3 comments
Closed

Prototypical Record Types? #141

JAForbes opened this issue Apr 28, 2017 · 3 comments
Assignees

Comments

@JAForbes
Copy link
Member

Currently $.RecordType checks a value via Object.keys. Object.keys will not pick up prototypical properties and methods.

I think it'd be pretty helpful to be able to define types that include prototypes.

E.g.

const $Promise = 
  $.RecordType({
    then: $.AnyFunction
    ,catch: $.AnyFunction
  })

Maybe $Promise isn't the best example, we'd probably want to use a BinaryType in that case. But even internally we could use the above in the validator for a BinaryType version for brevity.

@davidchambers
Copy link
Member

I agree. The Sanctuary way seems to be to respect enumerable keys, regardless of where they're defined. Would you like to submit a pull request for this change, James?

@JAForbes
Copy link
Member Author

Yeah sure 😄

@JAForbes JAForbes self-assigned this Apr 28, 2017
Avaq added a commit that referenced this issue Jun 30, 2017
@Avaq Avaq mentioned this issue Jun 30, 2017
7 tasks
@davidchambers
Copy link
Member

#164:

It would be a shame not to support prototypal inheritance, as I consider it one of the good parts of JavaScript. I suggest we state that a field is an enumerable property. Note that this means that Promise.resolve(42) is not a member of $.RecordType({then: $.AnyFunction}) as @JAForbes requested in #141. I can live with this. One could define an equivalent type via $.NullaryType (or even $.UnaryType).

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

No branches or pull requests

2 participants