File tree Expand file tree Collapse file tree 4 files changed +90
-0
lines changed
programs/type-intersection-reuse Expand file tree Collapse file tree 4 files changed +90
-0
lines changed Original file line number Diff line number Diff line change @@ -1550,6 +1550,26 @@ interface Foo {
15501550```
15511551
15521552
1553+ ## [ type-intersection-reuse] ( ./test/programs/type-intersection-reuse )
1554+
1555+ ``` ts
1556+ interface Type1 {
1557+ value1: string ;
1558+ value2: number ;
1559+ }
1560+ interface Type2 {
1561+ value2: number ;
1562+ value3: boolean ;
1563+ }
1564+
1565+ // Type1 can be reused, make sure value2 still works.
1566+ interface MyObject {
1567+ value1: Type1 ;
1568+ value2: Type1 & Type2 ;
1569+ }
1570+ ```
1571+
1572+
15531573## [ type-mapped-types] ( ./test/programs/type-mapped-types )
15541574
15551575``` ts
Original file line number Diff line number Diff line change 1+ interface Type1 {
2+ value1 : string ;
3+ value2 : number ;
4+ }
5+ interface Type2 {
6+ value2 : number ;
7+ value3 : boolean ;
8+ }
9+
10+ // Type1 can be reused, make sure value2 still works.
11+ interface MyObject {
12+ value1 : Type1 ;
13+ value2 : Type1 & Type2 ;
14+ }
Original file line number Diff line number Diff line change 1+ {
2+ "$schema" : " http://json-schema.org/draft-07/schema#" ,
3+ "additionalProperties" : false ,
4+ "definitions" : {
5+ "Type1" : {
6+ "additionalProperties" : false ,
7+ "properties" : {
8+ "value1" : {
9+ "type" : " string"
10+ },
11+ "value2" : {
12+ "type" : " number"
13+ }
14+ },
15+ "required" : [
16+ " value1" ,
17+ " value2"
18+ ],
19+ "type" : " object"
20+ }
21+ },
22+ "properties" : {
23+ "value1" : {
24+ "$ref" : " #/definitions/Type1"
25+ },
26+ "value2" : {
27+ "additionalProperties" : false ,
28+ "properties" : {
29+ "value1" : {
30+ "type" : " string"
31+ },
32+ "value2" : {
33+ "type" : " number"
34+ },
35+ "value3" : {
36+ "type" : " boolean"
37+ }
38+ },
39+ "required" : [
40+ " value1" ,
41+ " value2" ,
42+ " value3"
43+ ],
44+ "type" : " object"
45+ }
46+ },
47+ "required" : [
48+ " value1" ,
49+ " value2"
50+ ],
51+ "type" : " object"
52+ }
53+
Original file line number Diff line number Diff line change @@ -226,6 +226,9 @@ describe("schema", () => {
226226 assertSchema ( "type-intersection" , "MyObject" , {
227227 noExtraProps : true ,
228228 } ) ;
229+ assertSchema ( "type-intersection-reuse" , "MyObject" , {
230+ noExtraProps : true ,
231+ } ) ;
229232 assertSchema ( "type-union-tagged" , "Shape" ) ;
230233 assertSchema ( "type-aliases-union-namespace" , "MyModel" ) ;
231234 assertSchema ( "type-intersection-recursive" , "*" ) ;
You can’t perform that action at this time.
0 commit comments