Fix variance annotation
This commit is contained in:
1 parent
8b4eb339d4
commit
74923fa831
2 files changed
+28
-2
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Support `readonly` as a variance annotation (#19022 by @marcoww6)
|
||||
|
||||
Flow now accepts `readonly` as a property variance annotation, equivalent to `+` (covariant/read-only).
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
type T = {
|
||||
readonly foo: string,
|
||||
};
|
||||
|
||||
// Prettier stable
|
||||
SyntaxError
|
||||
|
||||
// Prettier main
|
||||
type T = {
|
||||
readonly foo: string,
|
||||
};
|
||||
```
|
||||
@@ -201,8 +201,15 @@ function printFlow(path, options, print) {
|
||||
return ["?", print("typeAnnotation")];
|
||||
case "Variance": {
|
||||
const { kind } = node;
|
||||
assert.ok(kind === "plus" || kind === "minus");
|
||||
return kind === "plus" ? "+" : "-";
|
||||
assert.ok(
|
||||
kind === "plus" ||
|
||||
kind === "minus" ||
|
||||
kind === "readonly" ||
|
||||
kind === "writeonly" ||
|
||||
kind === "in" ||
|
||||
kind === "out",
|
||||
);
|
||||
return kind === "plus" ? "+" : kind === "minus" ? "-" : `${kind} `;
|
||||
}
|
||||
case "KeyofTypeAnnotation":
|
||||
return ["keyof ", print("argument")];
|
||||
|
||||
Reference in new issue
Block a user