@@ -4,6 +4,7 @@ import { InvalidPointerError, isHandledError, normalizeError } from "./util/erro
44import { safePointerToPath , stripHash , getHash } from "./util/url.js" ;
55import type $Refs from "./refs.js" ;
66import type $RefParserOptions from "./options.js" ;
7+ import type { JSONSchema } from "./types" ;
78
89export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError ;
910
@@ -86,7 +87,7 @@ class $Ref {
8687 * @param options
8788 * @returns
8889 */
89- exists ( path : string , options : any ) {
90+ exists ( path : string , options ?: $RefParserOptions ) {
9091 try {
9192 this . resolve ( path , options ) ;
9293 return true ;
@@ -102,7 +103,7 @@ class $Ref {
102103 * @param options
103104 * @returns - Returns the resolved value
104105 */
105- get ( path : any , options : any ) {
106+ get ( path : any , options : $RefParserOptions ) {
106107 return this . resolve ( path , options ) ?. value ;
107108 }
108109
@@ -144,8 +145,7 @@ class $Ref {
144145 * @param path - The full path of the property to set, optionally with a JSON pointer in the hash
145146 * @param value - The value to assign
146147 */
147- set ( path : any , value : any ) {
148- // @ts -expect-error TS(2554): Expected 3 arguments, but got 2.
148+ set ( path : string , value : any ) {
149149 const pointer = new Pointer ( this , path ) ;
150150 this . value = pointer . set ( this . value , value ) ;
151151 }
@@ -156,8 +156,15 @@ class $Ref {
156156 * @param value - The value to inspect
157157 * @returns
158158 */
159- static is$Ref ( value : any ) : value is { $ref : string ; length ?: number } {
160- return value && typeof value === "object" && typeof value . $ref === "string" && value . $ref . length > 0 ;
159+ static is$Ref ( value : unknown ) : value is { $ref : string ; length ?: number } {
160+ return (
161+ Boolean ( value ) &&
162+ typeof value === "object" &&
163+ value !== null &&
164+ "$ref" in value &&
165+ typeof value . $ref === "string" &&
166+ value . $ref . length > 0
167+ ) ;
161168 }
162169
163170 /**
@@ -166,7 +173,7 @@ class $Ref {
166173 * @param value - The value to inspect
167174 * @returns
168175 */
169- static isExternal$Ref ( value : any ) : boolean {
176+ static isExternal$Ref ( value : unknown ) : boolean {
170177 return $Ref . is$Ref ( value ) && value . $ref ! [ 0 ] !== "#" ;
171178 }
172179
@@ -178,7 +185,7 @@ class $Ref {
178185 * @param options
179186 * @returns
180187 */
181- static isAllowed$Ref ( value : any , options : any ) {
188+ static isAllowed$Ref ( value : unknown , options ?: $RefParserOptions ) {
182189 if ( this . is$Ref ( value ) ) {
183190 if ( value . $ref . substring ( 0 , 2 ) === "#/" || value . $ref === "#" ) {
184191 // It's a JSON Pointer reference, which is always allowed
@@ -224,7 +231,7 @@ class $Ref {
224231 * @param value - The value to inspect
225232 * @returns
226233 */
227- static isExtended$Ref ( value : any ) {
234+ static isExtended$Ref ( value : unknown ) {
228235 return $Ref . is$Ref ( value ) && Object . keys ( value ) . length > 1 ;
229236 }
230237
@@ -259,7 +266,7 @@ class $Ref {
259266 * @param resolvedValue - The resolved value, which can be any type
260267 * @returns - Returns the dereferenced value
261268 */
262- static dereference ( $ref : $Ref , resolvedValue : any ) {
269+ static dereference ( $ref : $Ref , resolvedValue : JSONSchema ) : JSONSchema {
263270 if ( resolvedValue && typeof resolvedValue === "object" && $Ref . isExtended$Ref ( $ref ) ) {
264271 const merged = { } ;
265272 for ( const key of Object . keys ( $ref ) ) {
0 commit comments