@@ -4,6 +4,7 @@ import { InvalidPointerError, isHandledError, normalizeError } from "./util/erro
4
4
import { safePointerToPath , stripHash , getHash } from "./util/url.js" ;
5
5
import type $Refs from "./refs.js" ;
6
6
import type $RefParserOptions from "./options.js" ;
7
+ import type { JSONSchema } from "./types" ;
7
8
8
9
export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError ;
9
10
@@ -86,7 +87,7 @@ class $Ref {
86
87
* @param options
87
88
* @returns
88
89
*/
89
- exists ( path : string , options : any ) {
90
+ exists ( path : string , options ?: $RefParserOptions ) {
90
91
try {
91
92
this . resolve ( path , options ) ;
92
93
return true ;
@@ -102,7 +103,7 @@ class $Ref {
102
103
* @param options
103
104
* @returns - Returns the resolved value
104
105
*/
105
- get ( path : any , options : any ) {
106
+ get ( path : any , options : $RefParserOptions ) {
106
107
return this . resolve ( path , options ) ?. value ;
107
108
}
108
109
@@ -144,8 +145,7 @@ class $Ref {
144
145
* @param path - The full path of the property to set, optionally with a JSON pointer in the hash
145
146
* @param value - The value to assign
146
147
*/
147
- set ( path : any , value : any ) {
148
- // @ts -expect-error TS(2554): Expected 3 arguments, but got 2.
148
+ set ( path : string , value : any ) {
149
149
const pointer = new Pointer ( this , path ) ;
150
150
this . value = pointer . set ( this . value , value ) ;
151
151
}
@@ -156,8 +156,15 @@ class $Ref {
156
156
* @param value - The value to inspect
157
157
* @returns
158
158
*/
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
+ ) ;
161
168
}
162
169
163
170
/**
@@ -166,7 +173,7 @@ class $Ref {
166
173
* @param value - The value to inspect
167
174
* @returns
168
175
*/
169
- static isExternal$Ref ( value : any ) : boolean {
176
+ static isExternal$Ref ( value : unknown ) : boolean {
170
177
return $Ref . is$Ref ( value ) && value . $ref ! [ 0 ] !== "#" ;
171
178
}
172
179
@@ -178,7 +185,7 @@ class $Ref {
178
185
* @param options
179
186
* @returns
180
187
*/
181
- static isAllowed$Ref ( value : any , options : any ) {
188
+ static isAllowed$Ref ( value : unknown , options ?: $RefParserOptions ) {
182
189
if ( this . is$Ref ( value ) ) {
183
190
if ( value . $ref . substring ( 0 , 2 ) === "#/" || value . $ref === "#" ) {
184
191
// It's a JSON Pointer reference, which is always allowed
@@ -224,7 +231,7 @@ class $Ref {
224
231
* @param value - The value to inspect
225
232
* @returns
226
233
*/
227
- static isExtended$Ref ( value : any ) {
234
+ static isExtended$Ref ( value : unknown ) {
228
235
return $Ref . is$Ref ( value ) && Object . keys ( value ) . length > 1 ;
229
236
}
230
237
@@ -259,7 +266,7 @@ class $Ref {
259
266
* @param resolvedValue - The resolved value, which can be any type
260
267
* @returns - Returns the dereferenced value
261
268
*/
262
- static dereference ( $ref : $Ref , resolvedValue : any ) {
269
+ static dereference ( $ref : $Ref , resolvedValue : JSONSchema ) : JSONSchema {
263
270
if ( resolvedValue && typeof resolvedValue === "object" && $Ref . isExtended$Ref ( $ref ) ) {
264
271
const merged = { } ;
265
272
for ( const key of Object . keys ( $ref ) ) {
0 commit comments