@@ -4,6 +4,7 @@ import $Ref from "./ref.js";
44import * as url from "./util/url.js" ;
55import { JSONParserError , InvalidPointerError , MissingPointerError , isHandledError } from "./util/errors.js" ;
66import type { JSONSchema } from "./types" ;
7+ import type { JSONSchema4Type , JSONSchema6Type , JSONSchema7Type } from "json-schema" ;
78
89export const nullSymbol = Symbol ( "null" ) ;
910
@@ -90,7 +91,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
9091 */
9192 resolve ( obj : S , options ?: O , pathFromRoot ?: string ) {
9293 const tokens = Pointer . parse ( this . path , this . originalPath ) ;
93- const found : any = [ ] ;
94+ const found : string [ ] = [ ] ;
9495
9596 // Crawl the object, one token at a time
9697 this . value = unwrapOrThrow ( obj ) ;
@@ -163,7 +164,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
163164 * @returns
164165 * Returns the modified object, or an entirely new object if the entire object is overwritten.
165166 */
166- set ( obj : S , value : any , options ?: O ) {
167+ set ( obj : S , value : JSONSchema4Type | JSONSchema6Type | JSONSchema7Type , options ?: O ) {
167168 const tokens = Pointer . parse ( this . path ) ;
168169 let token ;
169170
@@ -190,7 +191,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
190191 }
191192
192193 // Set the value of the final token
193- resolveIf$Ref ( this , options ) ;
194+ resolveIf$Ref < S , O > ( this , options ) ;
194195 token = tokens [ tokens . length - 1 ] ;
195196 setValue ( this , token , value ) ;
196197
@@ -271,7 +272,11 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
271272 * @param [pathFromRoot] - the path of place that initiated resolving
272273 * @returns - Returns `true` if the resolution path changed
273274 */
274- function resolveIf$Ref ( pointer : any , options : any , pathFromRoot ?: any ) {
275+ function resolveIf$Ref < S extends object = JSONSchema , O extends ParserOptions < S > = ParserOptions < S > > (
276+ pointer : Pointer ,
277+ options : O | undefined ,
278+ pathFromRoot ?: string ,
279+ ) {
275280 // Is the value a JSON reference? (and allowed?)
276281
277282 if ( $Ref . isAllowed$Ref ( pointer . value , options ) ) {
@@ -291,7 +296,7 @@ function resolveIf$Ref(pointer: any, options: any, pathFromRoot?: any) {
291296 if ( $Ref . isExtended$Ref ( pointer . value ) ) {
292297 // This JSON reference "extends" the resolved value, rather than simply pointing to it.
293298 // So the resolved path does NOT change. Just the value does.
294- pointer . value = $Ref . dereference ( pointer . value , resolved . value ) ;
299+ pointer . value = $Ref . dereference ( pointer . value , resolved . value , options ) ;
295300 return false ;
296301 } else {
297302 // Resolve the reference
@@ -318,7 +323,7 @@ export default Pointer;
318323 * @param value - The value to assign
319324 * @returns - Returns the assigned value
320325 */
321- function setValue ( pointer : any , token : any , value : any ) {
326+ function setValue ( pointer : Pointer , token : string , value : JSONSchema4Type | JSONSchema6Type | JSONSchema7Type ) {
322327 if ( pointer . value && typeof pointer . value === "object" ) {
323328 if ( token === "-" && Array . isArray ( pointer . value ) ) {
324329 pointer . value . push ( value ) ;
@@ -333,14 +338,14 @@ function setValue(pointer: any, token: any, value: any) {
333338 return value ;
334339}
335340
336- function unwrapOrThrow ( value : any ) {
341+ function unwrapOrThrow ( value : unknown ) {
337342 if ( isHandledError ( value ) ) {
338343 throw value ;
339344 }
340345
341346 return value ;
342347}
343348
344- function isRootPath ( pathFromRoot : any ) : boolean {
349+ function isRootPath ( pathFromRoot : string | unknown ) : boolean {
345350 return typeof pathFromRoot == "string" && Pointer . parse ( pathFromRoot ) . length == 0 ;
346351}
0 commit comments