Add exact Param To ObjectTypeAnnotations (#7535)

This commit is contained in:
Will Monk
2018-03-09 18:22:01 +00:00
committed by Nicolò Ribaudo
parent 4f4dd3d4a6
commit 0389035e15
3 changed files with 24 additions and 3 deletions

View File

@@ -328,6 +328,23 @@ describe("programmatic generation", function() {
);
});
it("flow object exact", function() {
const objectStatement = t.objectTypeAnnotation(
[t.objectTypeProperty(t.identifier("bar"), t.stringTypeAnnotation())],
null,
null,
true,
);
const output = generate(objectStatement).code;
assert.equal(
output,
`{|
bar: string
|}`,
);
});
it("flow object indentation with empty leading ObjectTypeProperty", function() {
const objectStatement = t.objectTypeAnnotation(
[],

View File

@@ -1499,7 +1499,7 @@ Aliases: `UserWhitespacable`, `Property`, `ObjectMember`
### objectTypeAnnotation
```javascript
t.objectTypeAnnotation(properties, indexers, callProperties)
t.objectTypeAnnotation(properties, indexers, callProperties, exact)
```
See also `t.isObjectTypeAnnotation(node, opts)` and `t.assertObjectTypeAnnotation(node, opts)`.
@@ -1509,7 +1509,7 @@ Aliases: `Flow`, `FlowType`
- `properties`: `Array<ObjectTypeProperty | ObjectTypeSpreadProperty>` (required)
- `indexers`: `Array<ObjectTypeIndexer>` (default: `null`)
- `callProperties`: `Array<ObjectTypeCallProperty>` (default: `null`)
- `exact`: `boolean` (default: `null`)
- `exact`: `boolean` (default: `false`)
---

View File

@@ -252,13 +252,17 @@ defineType("NumberTypeAnnotation", {
defineType("ObjectTypeAnnotation", {
visitor: ["properties", "indexers", "callProperties"],
aliases: ["Flow", "FlowType"],
builder: ["properties", "indexers", "callProperties", "exact"],
fields: {
properties: validate(
arrayOfType(["ObjectTypeProperty", "ObjectTypeSpreadProperty"]),
),
indexers: validateOptional(arrayOfType("ObjectTypeIndexer")),
callProperties: validateOptional(arrayOfType("ObjectTypeCallProperty")),
exact: validate(assertValueType("boolean")),
exact: {
validate: assertValueType("boolean"),
default: false,
},
},
});