1

This seems like it should be in the documentation, but it isn't.

I have a shape type.

type ThisIsMyShapeType = shape(
  'some_prop' => bool,
);

How do I instantiate an object of this type ?

kneighbor
  • 23
  • 3

1 Answers1

1

You use the same shape keyword:

$x = shape(
  'some_prop' => true,
);

In Hack, shapes use structural typing so you don't need to declare your variable is a ThisIsMyShapeType -- the typechecker will verify that $x has all of the right fields to match the type.

There are quite a few examples in the official documentation.

Josh Watzman
  • 7,060
  • 1
  • 18
  • 26