diff --git a/lib/bundle.ts b/lib/bundle.ts index 7aed5a6b..d5aff2b7 100644 --- a/lib/bundle.ts +++ b/lib/bundle.ts @@ -14,7 +14,7 @@ import type { JSONSchema } from "./index"; * @param parser * @param options */ -function bundle( +function bundle = ParserOptions>( parser: $RefParser, options: O, ) { @@ -40,14 +40,14 @@ function bundle( +function crawl = ParserOptions>( parent: any, key: string | null, path: string, pathFromRoot: string, indirections: number, inventory: unknown[], - $refs: $Refs, + $refs: $Refs, options: O, ) { const obj = key === null ? parent : parent[key]; @@ -102,14 +102,14 @@ function crawl( +function inventory$Ref = ParserOptions>( $refParent: any, $refKey: any, path: string, pathFromRoot: any, indirections: any, inventory: any, - $refs: $Refs, + $refs: $Refs, options: O, ) { const $ref = $refKey === null ? $refParent : $refParent[$refKey]; diff --git a/lib/dereference.ts b/lib/dereference.ts index 1dc37b71..c767bad2 100644 --- a/lib/dereference.ts +++ b/lib/dereference.ts @@ -16,7 +16,7 @@ export default dereference; * @param parser * @param options */ -function dereference( +function dereference = ParserOptions>( parser: $RefParser, options: O, ) { @@ -48,14 +48,14 @@ function dereference( +function crawl = ParserOptions>( obj: any, path: string, pathFromRoot: string, parents: Set, processedObjects: Set, dereferencedCache: any, - $refs: $Refs, + $refs: $Refs, options: O, ) { let dereferenced; @@ -161,14 +161,14 @@ function crawl( +function dereference$Ref = ParserOptions>( $ref: any, path: string, pathFromRoot: string, parents: Set, processedObjects: any, dereferencedCache: any, - $refs: $Refs, + $refs: $Refs, options: O, ) { const isExternalRef = $Ref.isExternal$Ref($ref); diff --git a/lib/index.ts b/lib/index.ts index 6b03ec96..103ea726 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -37,7 +37,7 @@ export type RefParserSchema = string | JSONSchema; * * @class */ -export class $RefParser { +export class $RefParser = ParserOptions> { /** * The parsed (and possibly dereferenced) JSON schema object * @@ -52,7 +52,7 @@ export class $RefParser(); + $refs = new $Refs(); /** * Parses the given JSON schema. @@ -143,32 +143,34 @@ export class $RefParser(schema: S | string): Promise; - public static parse( + public static parse = ParserOptions>( + schema: S | string, + ): Promise; + public static parse = ParserOptions>( schema: S | string, callback: SchemaCallback, ): Promise; - public static parse( + public static parse = ParserOptions>( schema: S | string, options: O, ): Promise; - public static parse( + public static parse = ParserOptions>( schema: S | string, options: O, callback: SchemaCallback, ): Promise; - public static parse( + public static parse = ParserOptions>( baseUrl: string, schema: S | string, options: O, ): Promise; - public static parse( + public static parse = ParserOptions>( baseUrl: string, schema: S | string, options: O, callback: SchemaCallback, ): Promise; - public static parse(): + public static parse = ParserOptions>(): | Promise | Promise { const parser = new $RefParser(); @@ -186,12 +188,12 @@ export class $RefParser>; - public resolve(schema: S | string, callback: $RefsCallback): Promise; - public resolve(schema: S | string, options: O): Promise<$Refs>; - public resolve(schema: S | string, options: O, callback: $RefsCallback): Promise; - public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs>; - public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback): Promise; + public resolve(schema: S | string): Promise<$Refs>; + public resolve(schema: S | string, callback: $RefsCallback): Promise; + public resolve(schema: S | string, options: O): Promise<$Refs>; + public resolve(schema: S | string, options: O, callback: $RefsCallback): Promise; + public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs>; + public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback): Promise; async resolve() { const args = normalizeArgs(arguments); @@ -216,32 +218,34 @@ export class $RefParser(schema: S | string): Promise<$Refs>; - public static resolve( + public static resolve = ParserOptions>( + schema: S | string, + ): Promise<$Refs>; + public static resolve = ParserOptions>( schema: S | string, - callback: $RefsCallback, + callback: $RefsCallback, ): Promise; - public static resolve( + public static resolve = ParserOptions>( schema: S | string, options: O, - ): Promise<$Refs>; - public static resolve( + ): Promise<$Refs>; + public static resolve = ParserOptions>( schema: S | string, options: O, - callback: $RefsCallback, + callback: $RefsCallback, ): Promise; - public static resolve( + public static resolve = ParserOptions>( baseUrl: string, schema: S | string, options: O, - ): Promise<$Refs>; - public static resolve( + ): Promise<$Refs>; + public static resolve = ParserOptions>( baseUrl: string, schema: S | string, options: O, - callback: $RefsCallback, + callback: $RefsCallback, ): Promise; - static resolve(): + static resolve = ParserOptions>(): | Promise | Promise { const instance = new $RefParser(); @@ -259,34 +263,34 @@ export class $RefParser( + public static bundle = ParserOptions>( schema: S | string, ): Promise; - public static bundle( + public static bundle = ParserOptions>( schema: S | string, callback: SchemaCallback, ): Promise; - public static bundle( + public static bundle = ParserOptions>( schema: S | string, options: O, ): Promise; - public static bundle( + public static bundle = ParserOptions>( schema: S | string, options: O, callback: SchemaCallback, ): Promise; - public static bundle( + public static bundle = ParserOptions>( baseUrl: string, schema: S | string, options: O, ): Promise; - public static bundle( + public static bundle = ParserOptions>( baseUrl: string, schema: S | string, options: O, callback: SchemaCallback, ): Promise; - static bundle(): + static bundle = ParserOptions>(): | Promise | Promise { const instance = new $RefParser(); @@ -333,34 +337,34 @@ export class $RefParser( + public static dereference = ParserOptions>( schema: S | string, ): Promise; - public static dereference( + public static dereference = ParserOptions>( schema: S | string, callback: SchemaCallback, ): Promise; - public static dereference( + public static dereference = ParserOptions>( schema: S | string, options: O, ): Promise; - public static dereference( + public static dereference = ParserOptions>( schema: S | string, options: O, callback: SchemaCallback, ): Promise; - public static dereference( + public static dereference = ParserOptions>( baseUrl: string, schema: S | string, options: O, ): Promise; - public static dereference( + public static dereference = ParserOptions>( baseUrl: string, schema: S | string, options: O, callback: SchemaCallback, ): Promise; - static dereference(): + static dereference = ParserOptions>(): | Promise | Promise { const instance = new $RefParser(); @@ -400,7 +404,7 @@ export class $RefParser( +function finalize = ParserOptions>( parser: $RefParser, ) { const errors = JSONParserErrorGroup.getParserErrors(parser); diff --git a/lib/normalize-args.ts b/lib/normalize-args.ts index 8a0f3ca4..6bdc43ea 100644 --- a/lib/normalize-args.ts +++ b/lib/normalize-args.ts @@ -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 { +export interface NormalizedArguments = ParserOptions> { path: string; schema: S; - options: O & Options; + options: O & Options; callback: SchemaCallback; } /** * Normalizes the given arguments, accounting for optional args. */ -export function normalizeArgs( +export function normalizeArgs = ParserOptions>( _args: Partial, ): NormalizedArguments { let path; let schema; - let options: Options & O; + let options: Options & O; let callback; const args = Array.prototype.slice.call(_args) as any[]; diff --git a/lib/options.ts b/lib/options.ts index 7d4e1415..6a5b2c3a 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -174,7 +174,7 @@ export const getJsonSchemaRefParserDefaultOptions = () => { return defaults; }; -export const getNewOptions = ( +export const getNewOptions = = ParserOptions>( options: O | undefined, ): O & $RefParserOptions => { const newOptions = getJsonSchemaRefParserDefaultOptions(); @@ -183,8 +183,9 @@ export const getNewOptions = ; }; -export type Options = $RefParserOptions; -export type ParserOptions = DeepPartial<$RefParserOptions>; + +export type Options = $RefParserOptions; +export type ParserOptions = DeepPartial<$RefParserOptions>; /** * Merges the properties of the source object into the target object. * diff --git a/lib/parse.ts b/lib/parse.ts index 399122b7..6c9e1c01 100644 --- a/lib/parse.ts +++ b/lib/parse.ts @@ -9,15 +9,15 @@ import { isHandledError, } from "./util/errors.js"; import type $Refs from "./refs.js"; -import type { Options } from "./options.js"; +import type { ParserOptions } from "./options.js"; import type { FileInfo, JSONSchema } from "./types/index.js"; /** * Reads and parses the specified file path or URL. */ -async function parse( +async function parse = ParserOptions>( path: string, - $refs: $Refs, + $refs: $Refs, options: O, ) { // Remove the URL fragment, if any @@ -70,10 +70,10 @@ async function parse( +async function readFile = ParserOptions>( file: FileInfo, options: O, - $refs: $Refs, + $refs: $Refs, ): Promise { // console.log('Reading %s', file.url); @@ -116,10 +116,10 @@ async function readFile( +async function parseFile = ParserOptions>( file: FileInfo, options: O, - $refs: $Refs, + $refs: $Refs, ) { // Find the parsers that can read this file type. // If none of the parsers are an exact match for this file, then we'll try ALL of them. @@ -131,7 +131,7 @@ async function parseFile(parsers, "parse", file, $refs); + const parser = await plugins.run(parsers, "parse", file, $refs); if (!parser.plugin.allowEmpty && isEmpty(parser.result)) { throw ono.syntax(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`); } else { diff --git a/lib/pointer.ts b/lib/pointer.ts index c6cea28b..acbc8cbd 100644 --- a/lib/pointer.ts +++ b/lib/pointer.ts @@ -1,4 +1,4 @@ -import type $RefParserOptions from "./options.js"; +import type { ParserOptions } from "./options.js"; import $Ref from "./ref.js"; import * as url from "./util/url.js"; @@ -26,11 +26,11 @@ const safeDecodeURIComponent = (encodedURIComponent: string): string => { * @param [friendlyPath] - The original user-specified path (used for error messages) * @class */ -class Pointer { +class Pointer = ParserOptions> { /** * The {@link $Ref} object that contains this {@link Pointer} object. */ - $ref: $Ref; + $ref: $Ref; /** * The file path or URL, containing the JSON pointer in the hash. @@ -59,7 +59,7 @@ class Pointer { */ indirections: number; - constructor($ref: $Ref, path: string, friendlyPath?: string) { + constructor($ref: $Ref, path: string, friendlyPath?: string) { this.$ref = $ref; this.path = path; @@ -86,7 +86,7 @@ class Pointer { * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path * of the resolved value. */ - resolve(obj: any, options?: $RefParserOptions, pathFromRoot?: string) { + resolve(obj: any, options?: O, pathFromRoot?: string) { const tokens = Pointer.parse(this.path, this.originalPath); // Crawl the object, one token at a time @@ -144,7 +144,7 @@ class Pointer { * @returns * Returns the modified object, or an entirely new object if the entire object is overwritten. */ - set(obj: any, value: any, options?: $RefParserOptions) { + set(obj: any, value: any, options?: O) { const tokens = Pointer.parse(this.path); let token; diff --git a/lib/ref.ts b/lib/ref.ts index c026ac6a..ce549ddf 100644 --- a/lib/ref.ts +++ b/lib/ref.ts @@ -3,7 +3,6 @@ import type { JSONParserError, MissingPointerError, ParserError, ResolverError } import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js"; import { safePointerToPath, stripHash, getHash } from "./util/url.js"; import type $Refs from "./refs.js"; -import type $RefParserOptions from "./options.js"; import type { ParserOptions } from "./options.js"; import type { JSONSchema } from "./types"; @@ -14,7 +13,7 @@ export type $RefError = JSONParserError | ResolverError | ParserError | MissingP * * @class */ -class $Ref { +class $Ref = ParserOptions> { /** * The file path or URL of the referenced file. * This path is relative to the path of the main JSON schema file. @@ -40,7 +39,7 @@ class $Ref { * * @type {$Refs} */ - $refs: $Refs; + $refs: $Refs; /** * Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.) @@ -52,7 +51,7 @@ class $Ref { */ errors: Array<$RefError> = []; - constructor($refs: $Refs) { + constructor($refs: $Refs) { this.$refs = $refs; } @@ -88,7 +87,7 @@ class $Ref { * @param options * @returns */ - exists(path: string, options?: $RefParserOptions) { + exists(path: string, options?: O) { try { this.resolve(path, options); return true; @@ -104,7 +103,7 @@ class $Ref { * @param options * @returns - Returns the resolved value */ - get(path: string, options?: $RefParserOptions) { + get(path: string, options?: O) { return this.resolve(path, options)?.value; } @@ -117,8 +116,8 @@ class $Ref { * @param pathFromRoot - The path of `obj` from the schema root * @returns */ - resolve(path: string, options?: $RefParserOptions, friendlyPath?: string, pathFromRoot?: string) { - const pointer = new Pointer(this, path, friendlyPath); + resolve(path: string, options?: O, friendlyPath?: string, pathFromRoot?: string) { + const pointer = new Pointer(this, path, friendlyPath); try { return pointer.resolve(this.value, options, pathFromRoot); } catch (err: any) { @@ -186,7 +185,7 @@ class $Ref { * @param options * @returns */ - static isAllowed$Ref(value: unknown, options?: ParserOptions) { + static isAllowed$Ref(value: unknown, options?: ParserOptions) { if (this.is$Ref(value)) { if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") { // It's a JSON Pointer reference, which is always allowed @@ -267,7 +266,10 @@ class $Ref { * @param resolvedValue - The resolved value, which can be any type * @returns - Returns the dereferenced value */ - static dereference($ref: $Ref, resolvedValue: S): S { + static dereference = ParserOptions>( + $ref: $Ref, + resolvedValue: S, + ): S { if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) { const merged = {}; for (const key of Object.keys($ref)) { diff --git a/lib/refs.ts b/lib/refs.ts index a2cd418a..67553f43 100644 --- a/lib/refs.ts +++ b/lib/refs.ts @@ -2,12 +2,12 @@ import { ono } from "@jsdevtools/ono"; import $Ref from "./ref.js"; import * as url from "./util/url.js"; import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema"; -import type $RefParserOptions from "./options.js"; +import type { ParserOptions } from "./options.js"; import convertPathToPosix from "./util/convert-path-to-posix"; import type { JSONSchema } from "./types"; -interface $RefsMap { - [url: string]: $Ref; +interface $RefsMap = ParserOptions> { + [url: string]: $Ref; } /** * When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects. @@ -16,7 +16,7 @@ interface $RefsMap { * * See https://apitools.dev/json-schema-ref-parser/docs/refs.html */ -export default class $Refs { +export default class $Refs = ParserOptions> { /** * This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default. * @@ -84,7 +84,7 @@ export default class $Refs { * @param [options] * @returns - Returns the resolved value */ - get(path: string, options?: $RefParserOptions): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type { + get(path: string, options?: O): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type { return this._resolve(path, "", options)!.value; } @@ -112,7 +112,7 @@ export default class $Refs { * @returns * @protected */ - _get$Ref(path: any) { + _get$Ref(path: string) { path = url.resolve(this._root$Ref.path!, path); const withoutHash = url.stripHash(path); return this._$refs[withoutHash]; @@ -126,7 +126,7 @@ export default class $Refs { _add(path: string) { const withoutHash = url.stripHash(path); - const $ref = new $Ref(this); + const $ref = new $Ref(this); $ref.path = withoutHash; this._$refs[withoutHash] = $ref; @@ -144,7 +144,7 @@ export default class $Refs { * @returns * @protected */ - _resolve(path: string, pathFromRoot: string, options?: any) { + _resolve(path: string, pathFromRoot: string, options?: O) { const absPath = url.resolve(this._root$Ref.path!, path); const withoutHash = url.stripHash(absPath); const $ref = this._$refs[withoutHash]; @@ -162,7 +162,7 @@ export default class $Refs { * @type {object} * @protected */ - _$refs: $RefsMap = {}; + _$refs: $RefsMap = {}; /** * The {@link $Ref} object that is the root of the JSON schema. @@ -170,7 +170,7 @@ export default class $Refs { * @type {$Ref} * @protected */ - _root$Ref: $Ref; + _root$Ref: $Ref; constructor() { /** @@ -215,7 +215,10 @@ export default class $Refs { * @param [types] - Only return paths of the given types ("file", "http", etc.) * @returns */ -function getPaths($refs: $RefsMap, types: string[]) { +function getPaths = ParserOptions>( + $refs: $RefsMap, + types: string[], +) { let paths = Object.keys($refs); // Filter the paths by type diff --git a/lib/resolve-external.ts b/lib/resolve-external.ts index d51577b8..ef7fb6a7 100644 --- a/lib/resolve-external.ts +++ b/lib/resolve-external.ts @@ -4,7 +4,7 @@ import parse from "./parse.js"; import * as url from "./util/url.js"; import { isHandledError } from "./util/errors.js"; import type $Refs from "./refs.js"; -import type { Options, ParserOptions } from "./options.js"; +import type { ParserOptions } from "./options.js"; import type { JSONSchema } from "./types/index.js"; import type $RefParser from "./index.js"; @@ -18,11 +18,11 @@ import type $RefParser from "./index.js"; * The promise resolves once all JSON references in the schema have been resolved, * including nested references that are contained in externally-referenced files. */ -function resolveExternal( +function resolveExternal = ParserOptions>( parser: $RefParser, - options: Options, + options: O, ) { - if (!options.resolve.external) { + if (!options.resolve?.external) { // Nothing to resolve, so exit early return Promise.resolve(); } @@ -52,11 +52,11 @@ function resolveExternal( +function crawl = ParserOptions>( obj: string | Buffer | S | undefined | null, path: string, - $refs: $Refs, - options: Options, + $refs: $Refs, + options: O, seen?: Set, external?: boolean, ) { @@ -66,7 +66,7 @@ function crawl( if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) { seen.add(obj); // Track previously seen objects to avoid infinite recursion if ($Ref.isExternal$Ref(obj)) { - promises.push(resolve$Ref(obj, path, $refs, options)); + promises.push(resolve$Ref(obj, path, $refs, options)); } const keys = Object.keys(obj) as string[]; @@ -92,13 +92,13 @@ function crawl( * The promise resolves once all JSON references in the object have been resolved, * including nested references that are contained in externally-referenced files. */ -async function resolve$Ref( +async function resolve$Ref = ParserOptions>( $ref: S, path: string, - $refs: $Refs, - options: Options, + $refs: $Refs, + options: O, ) { - const shouldResolveOnCwd = options.dereference.externalReferenceResolution === "root"; + const shouldResolveOnCwd = options.dereference?.externalReferenceResolution === "root"; const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref!); const withoutHash = url.stripHash(resolvedPath); diff --git a/lib/types/index.ts b/lib/types/index.ts index 66e77448..1e3a33df 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -7,11 +7,15 @@ import type { JSONSchema7Object, } from "json-schema"; import type $Refs from "../refs.js"; +import type { ParserOptions } from "../options"; export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7; export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object; export type SchemaCallback = (err: Error | null, schema?: S | object | null) => any; -export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any; +export type $RefsCallback = ParserOptions> = ( + err: Error | null, + $refs?: $Refs, +) => any; /** * See https://apitools.dev/json-schema-ref-parser/docs/options.html diff --git a/lib/util/errors.ts b/lib/util/errors.ts index db8c17c4..5d53b3a7 100644 --- a/lib/util/errors.ts +++ b/lib/util/errors.ts @@ -39,7 +39,7 @@ export class JSONParserError extends Error { export class JSONParserErrorGroup< S extends JSONSchema = JSONSchema, - O extends ParserOptions = ParserOptions, + O extends ParserOptions = ParserOptions, > extends Error { files: $RefParser; @@ -55,12 +55,12 @@ export class JSONParserErrorGroup< Ono.extend(this); } - static getParserErrors( + static getParserErrors = ParserOptions>( parser: $RefParser, ) { const errors = []; - for (const $ref of Object.values(parser.$refs._$refs) as $Ref[]) { + for (const $ref of Object.values(parser.$refs._$refs) as $Ref[]) { if ($ref.errors) { errors.push(...$ref.errors); } @@ -78,7 +78,7 @@ export class JSONParserErrorGroup< | UnmatchedParserError | UnmatchedResolverError > { - return JSONParserErrorGroup.getParserErrors(this.files); + return JSONParserErrorGroup.getParserErrors(this.files); } } diff --git a/lib/util/plugins.ts b/lib/util/plugins.ts index a5baeff0..6dfb1c60 100644 --- a/lib/util/plugins.ts +++ b/lib/util/plugins.ts @@ -1,5 +1,5 @@ import type { FileInfo, JSONSchema } from "../types/index.js"; -import type $RefParserOptions from "../options.js"; +import type { ParserOptions } from "../options.js"; import type { ResolverOptions } from "../types/index.js"; import type $Refs from "../refs.js"; import type { Plugin } from "../types/index.js"; @@ -10,14 +10,16 @@ import type { Plugin } from "../types/index.js"; * * @returns */ -export function all(plugins: $RefParserOptions["resolve"]): Plugin[] { - return Object.keys(plugins) +export function all = ParserOptions>( + plugins: O["resolve"], +): Plugin[] { + return (Object.keys(plugins || {}) as (keyof ResolverOptions)[]) .filter((key) => { - return typeof plugins[key] === "object"; + return typeof plugins![key] === "object"; }) .map((key) => { - (plugins[key] as ResolverOptions)!.name = key; - return plugins[key] as Plugin; + (plugins![key] as ResolverOptions)!.name = key; + return plugins![key] as Plugin; }); } @@ -43,7 +45,7 @@ export function sort(plugins: Plugin[]) { }); } -export interface PluginResult { +export interface PluginResult = ParserOptions> { plugin: Plugin; result?: string | Buffer | S; error?: any; @@ -57,17 +59,17 @@ export interface PluginResult { * If the promise rejects, or the callback is called with an error, then the next plugin is called. * If ALL plugins fail, then the last error is thrown. */ -export async function run( +export async function run = ParserOptions>( plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions, file: FileInfo, - $refs: $Refs, + $refs: $Refs, ) { let plugin: Plugin; - let lastError: PluginResult; + let lastError: PluginResult; let index = 0; - return new Promise>((resolve, reject) => { + return new Promise>((resolve, reject) => { runNextPlugin(); function runNextPlugin() { @@ -94,7 +96,7 @@ export async function run( } } - function callback(err: PluginResult["error"], result: PluginResult["result"]) { + function callback(err: PluginResult["error"], result: PluginResult["result"]) { if (err) { onError(err); } else { @@ -102,7 +104,7 @@ export async function run( } } - function onSuccess(result: PluginResult["result"]) { + function onSuccess(result: PluginResult["result"]) { // console.log(' success'); resolve({ plugin, @@ -110,7 +112,7 @@ export async function run( }); } - function onError(error: PluginResult["error"]) { + function onError(error: PluginResult["error"]) { // console.log(' %s', err.message || err); lastError = { plugin, @@ -127,12 +129,12 @@ export async function run( * If the value is a RegExp, then it will be tested against the file URL. * If the value is an array, then it will be compared against the file extension. */ -function getResult( +function getResult = ParserOptions>( obj: Plugin, prop: keyof Plugin | keyof ResolverOptions, file: FileInfo, callback?: (err?: Error, result?: any) => void, - $refs?: any, + $refs?: $Refs, ) { const value = obj[prop as keyof typeof obj] as unknown;