Skip to content

Commit

Permalink
fix(types): fix types of options, inheritance globally
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Mar 6, 2024
1 parent a3d1801 commit 482dff1
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 127 deletions.
10 changes: 5 additions & 5 deletions lib/bundle.ts
Expand Up @@ -14,7 +14,7 @@ import type { JSONSchema } from "./index";
* @param parser
* @param options
*/
function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
options: O,
) {
Expand All @@ -40,14 +40,14 @@ function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = Par
* @param $refs
* @param options
*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parent: any,
key: string | null,
path: string,
pathFromRoot: string,
indirections: number,
inventory: unknown[],
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,
) {
const obj = key === null ? parent : parent[key];
Expand Down Expand Up @@ -102,14 +102,14 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = Pars
* @param $refs
* @param options
*/
function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$refParent: any,
$refKey: any,
path: string,
pathFromRoot: any,
indirections: any,
inventory: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,
) {
const $ref = $refKey === null ? $refParent : $refParent[$refKey];
Expand Down
10 changes: 5 additions & 5 deletions lib/dereference.ts
Expand Up @@ -16,7 +16,7 @@ export default dereference;
* @param parser
* @param options
*/
function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
options: O,
) {
Expand Down Expand Up @@ -48,14 +48,14 @@ function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions
* @param options
* @returns
*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
obj: any,
path: string,
pathFromRoot: string,
parents: Set<any>,
processedObjects: Set<any>,
dereferencedCache: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,
) {
let dereferenced;
Expand Down Expand Up @@ -161,14 +161,14 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = Pars
* @param options
* @returns
*/
function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: any,
path: string,
pathFromRoot: string,
parents: Set<any>,
processedObjects: any,
dereferencedCache: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,
) {
const isExternalRef = $Ref.isExternal$Ref($ref);
Expand Down
88 changes: 46 additions & 42 deletions lib/index.ts
Expand Up @@ -37,7 +37,7 @@ export type RefParserSchema = string | JSONSchema;
*
* @class
*/
export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The parsed (and possibly dereferenced) JSON schema object
*
Expand All @@ -52,7 +52,7 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @type {$Refs}
* @readonly
*/
$refs = new $Refs<S>();
$refs = new $Refs<S, O>();

/**
* Parses the given JSON schema.
Expand Down Expand Up @@ -143,32 +143,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
}
}

public static parse<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 146 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 149 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const parser = new $RefParser<S, O>();
Expand All @@ -186,12 +188,12 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @param options (optional)
* @param callback (optional) A callback that will receive a `$Refs` object
*/
public resolve(schema: S | string): Promise<$Refs<S>>;
public resolve(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
public resolve(schema: S | string, options: O): Promise<$Refs<S>>;
public resolve(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
public resolve(schema: S | string): Promise<$Refs<S, O>>;
public resolve(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
public resolve(schema: S | string, options: O): Promise<$Refs<S, O>>;
public resolve(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
async resolve() {
const args = normalizeArgs<S, O>(arguments);

Expand All @@ -216,32 +218,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @param options (optional)
* @param callback (optional) A callback that will receive a `$Refs` object
*/
public static resolve<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: $RefsCallback<S>,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: $RefsCallback<S>,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: $RefsCallback<S>,
callback: $RefsCallback<S, O>,
): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand All @@ -259,34 +263,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @param options (optional)
* @param callback (optional) A callback that will receive the bundled schema object
*/
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 266 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 269 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<void>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand Down Expand Up @@ -333,34 +337,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @param options (optional)
* @param callback (optional) A callback that will receive the dereferenced schema object
*/
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 340 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node lts/* on macos-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node current on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 343 in lib/index.ts

View workflow job for this annotation

GitHub Actions / Node 18 on windows-latest

'O' is defined but never used. Allowed unused vars must match /^_/u
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<void>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: SchemaCallback<S>,
): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand Down Expand Up @@ -400,7 +404,7 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
}
export default $RefParser;

function finalize<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function finalize<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
) {
const errors = JSONParserErrorGroup.getParserErrors(parser);
Expand Down
8 changes: 4 additions & 4 deletions lib/normalize-args.ts
Expand Up @@ -4,21 +4,21 @@ import type { JSONSchema, SchemaCallback } from "./types";

// I really dislike this function and the way it's written. It's not clear what it's doing, and it's way too flexible
// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
path: string;
schema: S;
options: O & Options;
options: O & Options<S>;
callback: SchemaCallback<S>;
}
/**
* Normalizes the given arguments, accounting for optional args.
*/
export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
_args: Partial<IArguments>,
): NormalizedArguments<S, O> {
let path;
let schema;
let options: Options & O;
let options: Options<S> & O;
let callback;
const args = Array.prototype.slice.call(_args) as any[];

Expand Down
7 changes: 4 additions & 3 deletions lib/options.ts
Expand Up @@ -174,7 +174,7 @@ export const getJsonSchemaRefParserDefaultOptions = () => {
return defaults;
};

export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
options: O | undefined,
): O & $RefParserOptions<S> => {
const newOptions = getJsonSchemaRefParserDefaultOptions();
Expand All @@ -183,8 +183,9 @@ export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends Parse
}
return newOptions as O & $RefParserOptions<S>;
};
export type Options = $RefParserOptions<JSONSchema>;
export type ParserOptions = DeepPartial<$RefParserOptions<JSONSchema>>;

export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
/**
* Merges the properties of the source object into the target object.
*
Expand Down

0 comments on commit 482dff1

Please sign in to comment.