好的,所以我得到了一个私有的 ?Vector $lines,它在构造对象时是空的,现在我想向该向量添加字符串。以下Hack代码运行良好:
<?hh
class LineList {
private ?Vector<string> $lines;
public function addLine(string $line): void {
$this->file[] = trim($line);
}
}
但是当使用 hh_client 检查代码时,它给了我以下警告:
$this->file[]]: a nullable type does not allow array append (Typing[4006])
[private ?Vector<string> $lines]: You might want to check this out
问题:如何在检查器不推送此警告的情况下向 Vector 添加元素?