facebook / facebook/hhvm

Hack: Allow extending shapes

Open
#7,130 9 comments 3 reactions 0 assignees View on GitHub
feature request hack
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

We're starting to move towards using shapes as option arguments and are having to duplicate most of the declaration between subclasses, which leads to problems when changing the base class.

Contrived example:

``` hack
int,
'b' => ?string,
);

type BOptions = shape(
'a' => int,
'b' => ?string,
'c' => (function():void),
);

class A {
public function __construct(protected AOptions $options) {}
}

class B extends A {
protected (function():void) $c;

public function __construct(BOptions $options) {
$this->c = $options['c'];
parent::__construct($options);
}
}
```

Being able to have `BOptions` extend `AOptions` would reduce the copy pasta and chance of errors. Something like:

``` hack
type BOptions = shape(
'c' => (function():void),
) extends AOptions;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.