File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed
valid-data/array-function-generics Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 11import ts from "typescript" ;
2- import { Context , NodeParser } from "../NodeParser.js" ;
3- import { SubNodeParser } from "../SubNodeParser.js" ;
2+ import type { Context , NodeParser } from "../NodeParser.js" ;
3+ import type { SubNodeParser } from "../SubNodeParser.js" ;
4+ import { AnyType } from "../Type/AnyType.js" ;
45import { ArrayType } from "../Type/ArrayType.js" ;
5- import { BaseType } from "../Type/BaseType.js" ;
6+ import type { BaseType } from "../Type/BaseType.js" ;
67
78export class ArrayNodeParser implements SubNodeParser {
89 public constructor ( protected childNodeParser : NodeParser ) { }
@@ -13,6 +14,7 @@ export class ArrayNodeParser implements SubNodeParser {
1314
1415 public createType ( node : ts . ArrayTypeNode , context : Context ) : BaseType {
1516 const type = this . childNodeParser . createType ( node . elementType , context ) ;
16- return new ArrayType ( type ) ;
17+ // Generics without `extends` or `defaults` cannot be resolved, so we fallback to `any`
18+ return new ArrayType ( type ?? new AnyType ( ) ) ;
1719 }
1820}
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ describe("valid-data-other", () => {
7878 it ( "array-min-items-2" , assertValidSchema ( "array-min-items-2" , "MyType" ) ) ;
7979 it ( "array-min-max-items" , assertValidSchema ( "array-min-max-items" , "MyType" ) ) ;
8080 it ( "array-min-max-items-optional" , assertValidSchema ( "array-min-max-items-optional" , "MyType" ) ) ;
81+ it ( "array-function-generics" , assertValidSchema ( "array-function-generics" , "*" ) ) ;
8182 it ( "array-max-items-optional" , assertValidSchema ( "array-max-items-optional" , "MyType" ) ) ;
8283 it ( "shorthand-array" , assertValidSchema ( "shorthand-array" , "MyType" ) ) ;
8384
Original file line number Diff line number Diff line change 1+ export function arrayGenerics < T > ( a : T [ ] , b : T [ ] ) : T [ ] {
2+ console . log ( a , b ) ;
3+ return b ;
4+ }
Original file line number Diff line number Diff line change 1+ {
2+ "$ref" : " #/definitions/arrayGenerics" ,
3+ "$schema" : " http://json-schema.org/draft-07/schema#" ,
4+ "definitions" : {
5+ "arrayGenerics" : {
6+ "$comment" : " (a: T[], b: T[]) => T[]" ,
7+ "type" : " object" ,
8+ "properties" : {
9+ "namedArgs" : {
10+ "type" : " object" ,
11+ "properties" : {
12+ "a" : {
13+ "type" : " array" ,
14+ "items" : {}
15+ },
16+ "b" : {
17+ "type" : " array" ,
18+ "items" : {}
19+ }
20+ },
21+ "required" : [
22+ " a" ,
23+ " b"
24+ ],
25+ "additionalProperties" : false
26+ }
27+ }
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments