Skip to content

Commit

Permalink
Test type intersection with reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
laat committed Nov 26, 2020
1 parent 5fa6fd4 commit fa17c73
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,26 @@ interface Foo {
```


## [type-intersection-reuse](./test/programs/type-intersection-reuse)

```ts
interface Type1 {
value1: string;
value2: number;
}
interface Type2 {
value2: number;
value3: boolean;
}

// Type1 can be reused, make sure value2 still works.
interface MyObject {
value1: Type1;
value2: Type1 & Type2;
}
```


## [type-mapped-types](./test/programs/type-mapped-types)

```ts
Expand Down
14 changes: 14 additions & 0 deletions test/programs/type-intersection-reuse/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface Type1 {
value1: string;
value2: number;
}
interface Type2 {
value2: number;
value3: boolean;
}

// Type1 can be reused, make sure value2 still works.
interface MyObject {
value1: Type1;
value2: Type1 & Type2;
}
53 changes: 53 additions & 0 deletions test/programs/type-intersection-reuse/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"definitions": {
"Type1": {
"additionalProperties": false,
"properties": {
"value1": {
"type": "string"
},
"value2": {
"type": "number"
}
},
"required": [
"value1",
"value2"
],
"type": "object"
}
},
"properties": {
"value1": {
"$ref": "#/definitions/Type1"
},
"value2": {
"additionalProperties": false,
"properties": {
"value1": {
"type": "string"
},
"value2": {
"type": "number"
},
"value3": {
"type": "boolean"
}
},
"required": [
"value1",
"value2",
"value3"
],
"type": "object"
}
},
"required": [
"value1",
"value2"
],
"type": "object"
}

3 changes: 3 additions & 0 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ describe("schema", () => {
assertSchema("type-intersection", "MyObject", {
noExtraProps: true,
});
assertSchema("type-intersection-reuse", "MyObject", {
noExtraProps: true,
});
assertSchema("type-union-tagged", "Shape");
assertSchema("type-aliases-union-namespace", "MyModel");
assertSchema("type-intersection-recursive", "*");
Expand Down

0 comments on commit fa17c73

Please sign in to comment.