type-assert icon indicating copy to clipboard operation
type-assert copied to clipboard

[ RFC ] Do we want to open up using custom TypeSpec<T>'s for the reified API's?

Open lexidor opened this issue 4 years ago • 4 comments

With the current capabilities of TypeAssert, we can derive from Facebook\TypeSpec\TypeSpec<T> to implement validation for custom newtypes. These specs compose just like the built-in specs.

__Private\from_type_structure<T>() (and its friends like TypeSpec\of<T>()) will however not know how to find our custom TypeSpecs. This means that you need to manually build the complex TypeSpec object via TypeSpec\xxx() calls in practice.

Do we want to offer the capability to supply your own TypeSpecs for your own newtypes and have them be recognized by TypeSpec\of<T>() and friends?

This has the major downside of revealing how TypeSpec\of<T>() works and will prevent us from changing our implementation away from TypeStrucuture<T>. The fact that we use TypeStrucuture<T> is an implementation detail of this library.

I have created a PR which demonstrates how something like this may work. I am not suggesting that this is the PR that adds this feature. I just need to be able to point to some example code.

lexidor avatar May 20 '20 16:05 lexidor