@@ -353,12 +353,30 @@ describe("JTDSchemaType", () => {
353353 } )
354354
355355 it ( "should typecheck ref schemas" , ( ) => {
356+ const ajv = new _Ajv ( )
356357 const refs : JTDSchemaType < number [ ] , { num : number } > = {
357358 definitions : {
358359 num : { type : "float64" } ,
359360 } ,
360361 elements : { ref : "num" } ,
361362 }
363+
364+ // test that ajv.validate captures ref data type
365+ const validData : unknown = [ 0 ]
366+ if ( ajv . validate ( refs , validData ) ) {
367+ const postValidation : number [ ] = validData
368+ postValidation [ 0 ] . should . equal ( 0 )
369+ }
370+ should . not . exist ( ajv . errors )
371+
372+ // test that ajv.compile captures ref data type
373+ const validate = ajv . compile ( refs )
374+ if ( validate ( validData ) ) {
375+ const postValidation : number [ ] = validData
376+ postValidation [ 0 ] . should . equal ( 0 )
377+ }
378+ should . not . exist ( validate . errors )
379+
362380 const missingDef : JTDSchemaType < number [ ] , { num : number } > = {
363381 // @ts -expect-error
364382 definitions : { } ,
@@ -393,6 +411,35 @@ describe("JTDSchemaType", () => {
393411 void [ refs , missingDef , missingType , nullRefs , refsNullOne , refsNullTwo ]
394412 } )
395413
414+ it ( "should typecheck nested ref schemas" , ( ) => {
415+ const ajv = new _Ajv ( )
416+ const schema : JTDSchemaType < { str : string ; ref : number } , { num : number } > = {
417+ definitions : {
418+ num : { type : "int32" } ,
419+ } ,
420+ properties : {
421+ ref : { ref : "num" } ,
422+ str : { type : "string" } ,
423+ } ,
424+ }
425+
426+ // test that ajv.validate captures ref data type
427+ const validData : unknown = { str : "" , ref : 0 }
428+ if ( ajv . validate ( schema , validData ) ) {
429+ const str : string = validData . str
430+ str . should . equal ( "" )
431+ }
432+ should . not . exist ( ajv . errors )
433+
434+ // test that ajv.compile captures ref data type
435+ const validate = ajv . compile ( schema )
436+ if ( validate ( validData ) ) {
437+ const str : string = validData . str
438+ str . should . equal ( "" )
439+ }
440+ should . not . exist ( validate . errors )
441+ } )
442+
396443 it ( "should typecheck metadata schemas" , ( ) => {
397444 const meta : JTDSchemaType < number > = { type : "float32" , metadata : { key : "val" } }
398445 const emptyMeta : JTDSchemaType < unknown > = { metadata : { key : "val" } }
0 commit comments