facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

propType.func that accepts a specific type of argument #210

Closed haldunanil closed 6 years ago

haldunanil commented 6 years ago

Hi!

I'm looking to create a propType for a function that specifically must receive as its only argument an array containing File objects. Is there a way to do this natively or do I have to make a custom propType?

Thanks!

ljharb commented 6 years ago

There's no way to verify that with JavaScript without actually calling the function, which doesn't happen at prop verification time. The function itself needs to verify its arguments, at runtime - the best a propType could do is assert that the function's .length is 1.

Another alternative is with adding a type system like Flow or TypeScript on top of JS.

haldunanil commented 6 years ago

Got it, that makes sense. Thanks!