Skip to content

Commit

Permalink
fix(types): make default type extend base object instead of JSONSchem…
Browse files Browse the repository at this point in the history
…a to support non-spec compliant type overloads
  • Loading branch information
jonluca committed Mar 6, 2024
1 parent 482dff1 commit 7a8806d
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 76 deletions.
6 changes: 3 additions & 3 deletions lib/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { JSONSchema } from "./index";
* @param parser
* @param options
*/
function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
options: O,
) {
Expand All @@ -40,7 +40,7 @@ function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> =
* @param $refs
* @param options
*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parent: any,
key: string | null,
path: string,
Expand Down Expand Up @@ -102,7 +102,7 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = P
* @param $refs
* @param options
*/
function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function inventory$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$refParent: any,
$refKey: any,
path: string,
Expand Down
6 changes: 3 additions & 3 deletions lib/dereference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default dereference;
* @param parser
* @param options
*/
function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
options: O,
) {
Expand Down Expand Up @@ -48,7 +48,7 @@ function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<
* @param options
* @returns
*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
obj: any,
path: string,
pathFromRoot: string,
Expand Down Expand Up @@ -161,7 +161,7 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = P
* @param options
* @returns
*/
function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: any,
path: string,
pathFromRoot: string,
Expand Down
64 changes: 32 additions & 32 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type RefParserSchema = string | JSONSchema;
*
* @class
*/
export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The parsed (and possibly dereferenced) JSON schema object
*
Expand Down Expand Up @@ -94,10 +94,10 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
if (url.isFileSystemPath(args.path)) {
args.path = url.fromFileSystemPath(args.path);
pathType = "file";
} else if (!args.path && args.schema && args.schema.$id) {
} else if (!args.path && args.schema && "$id" in args.schema && args.schema.$id) {
// when schema id has defined an URL should use that hostname to request the references,
// instead of using the current page URL
const params = url.parse(args.schema.$id);
const params = url.parse(args.schema.$id as string);
const port = params.protocol === "https:" ? 443 : 80;

args.path = `${params.protocol}//${params.hostname}:${port}`;
Expand Down Expand Up @@ -143,34 +143,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
}
}

public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static parse<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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>>(
public static parse<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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<S> = ParserOptions<S>>(
public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static parse<S extends object = 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<S> = ParserOptions<S>>(
public static parse<S extends object = 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<S> = ParserOptions<S>>(
public static parse<S extends object = 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<S> = ParserOptions<S>>():
public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const parser = new $RefParser<S, O>();
Expand Down Expand Up @@ -218,34 +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, O extends ParserOptions<S> = ParserOptions<S>>(
public static resolve<S extends object = 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>>(
public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: $RefsCallback<S, O>,
): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand All @@ -263,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<S> = ParserOptions<S>>(
public static bundle<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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<S> = ParserOptions<S>>(
public static bundle<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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<S> = ParserOptions<S>>(
public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static bundle<S extends object = 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<S> = ParserOptions<S>>(
public static bundle<S extends object = 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<S> = ParserOptions<S>>(
public static bundle<S extends object = 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<S> = ParserOptions<S>>():
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand Down Expand Up @@ -337,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<S> = ParserOptions<S>>(
public static dereference<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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<S> = ParserOptions<S>>(
public static dereference<S extends object = 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 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 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 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 18 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 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 lts/* on macos-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<S> = ParserOptions<S>>(
public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static dereference<S extends object = 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<S> = ParserOptions<S>>(
public static dereference<S extends object = 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<S> = ParserOptions<S>>(
public static dereference<S extends object = 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<S> = ParserOptions<S>>():
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>
| Promise<void> {
const instance = new $RefParser<S, O>();
Expand Down Expand Up @@ -404,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<S> = ParserOptions<S>>(
function finalize<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
) {
const errors = JSONParserErrorGroup.getParserErrors(parser);
Expand Down
4 changes: 2 additions & 2 deletions lib/normalize-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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<S> = ParserOptions<S>> {
export interface NormalizedArguments<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
path: string;
schema: S;
options: O & Options<S>;
Expand All @@ -13,7 +13,7 @@ export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extend
/**
* Normalizes the given arguments, accounting for optional args.
*/
export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
export function normalizeArgs<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
_args: Partial<IArguments>,
): NormalizedArguments<S, O> {
let path;
Expand Down
8 changes: 4 additions & 4 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface DereferenceOptions {
* @param [options] - Overridden options
* @class
*/
export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
export interface $RefParserOptions<S extends object = JSONSchema> {
/**
* The `parse` options determine how different types of files will be parsed.
*
Expand Down Expand Up @@ -174,7 +174,7 @@ export const getJsonSchemaRefParserDefaultOptions = () => {
return defaults;
};

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

export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
export type Options<S extends object = JSONSchema> = $RefParserOptions<S>;
export type ParserOptions<S extends object = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
/**
* Merges the properties of the source object into the target object.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { FileInfo, JSONSchema } from "./types/index.js";
/**
* Reads and parses the specified file path or URL.
*/
async function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
async function parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
path: string,
$refs: $Refs<S, O>,
options: O,
Expand Down Expand Up @@ -70,7 +70,7 @@ async function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<
* @returns
* The promise resolves with the raw file contents and the resolver that was used.
*/
async function readFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
async function readFile<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
file: FileInfo,
options: O,
$refs: $Refs<S, O>,
Expand Down Expand Up @@ -116,7 +116,7 @@ async function readFile<S extends JSONSchema = JSONSchema, O extends ParserOptio
* @returns
* The promise resolves with the parsed file contents and the parser that was used.
*/
async function parseFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
async function parseFile<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
file: FileInfo,
options: O,
$refs: $Refs<S, O>,
Expand Down
6 changes: 3 additions & 3 deletions lib/pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const safeDecodeURIComponent = (encodedURIComponent: string): string => {
* @param [friendlyPath] - The original user-specified path (used for error messages)
* @class
*/
class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The {@link $Ref} object that contains this {@link Pointer} object.
*/
Expand Down Expand Up @@ -86,7 +86,7 @@ class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Pa
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
* of the resolved value.
*/
resolve(obj: any, options?: O, pathFromRoot?: string) {
resolve(obj: S, options?: O, pathFromRoot?: string) {
const tokens = Pointer.parse(this.path, this.originalPath);

// Crawl the object, one token at a time
Expand Down Expand Up @@ -144,7 +144,7 @@ class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Pa
* @returns
* Returns the modified object, or an entirely new object if the entire object is overwritten.
*/
set(obj: any, value: any, options?: O) {
set(obj: S, value: any, options?: O) {
const tokens = Pointer.parse(this.path);
let token;

Expand Down
6 changes: 3 additions & 3 deletions lib/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type $RefError = JSONParserError | ResolverError | ParserError | MissingP
*
* @class
*/
class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The file path or URL of the referenced file.
* This path is relative to the path of the main JSON schema file.
Expand Down Expand Up @@ -185,7 +185,7 @@ class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Parse
* @param options
* @returns
*/
static isAllowed$Ref<S extends JSONSchema = JSONSchema>(value: unknown, options?: ParserOptions<S>) {
static isAllowed$Ref<S extends object = JSONSchema>(value: unknown, options?: ParserOptions<S>) {
if (this.is$Ref(value)) {
if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") {
// It's a JSON Pointer reference, which is always allowed
Expand Down Expand Up @@ -266,7 +266,7 @@ class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Parse
* @param resolvedValue - The resolved value, which can be any type
* @returns - Returns the dereferenced value
*/
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: $Ref<S, O>,
resolvedValue: S,
): S {
Expand Down
Loading

0 comments on commit 7a8806d

Please sign in to comment.