Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test type intersection with reuse #388

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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