Closed runk closed 3 years ago
Hmmm... weird. I think it's confusing the class
definition and the namespace
definition. Not sure how to fix that though. If you know how, I'd be happy to accept a PR.
Have you tried using @jsdevtools/json-schema-ref-parser
instead? The un-scoped json-schema-ref-parser
package is just a wrapper around the scoped package. Maybe the wrapper layer is confusing TypeScript, and directly using the underlying package might work.
Yup can confirm this works:
import $RefParser from '@apidevtools/json-schema-ref-parser';
const refParser = new $RefParser();
Okay, cool. Then TypeScript is just getting confused by the wrapper module. I'm sure there's some way to change the wrapper type definition to un-confuse TypeScript, but I don't know what that syntax would be.
Definitely getting confused, as when i do this
import $RefParser from 'json-schema-ref-parser';
console.log($RefParser.dereference);
I get the error
TS2339: Property 'dereference' does not exist on type 'typeof $RefParser'.
Even though in the definition file, it includes a static function
Renamed the namespace $RefParser to $RefParser2 in the index.d.ts and it compiled correctly without error
Ok looks like the problem is with json-schema-ref-parser... if i replace
import $RefParser from 'json-schema-ref-parser';
with
import $RefParser from '@apidevtools/json-schema-ref-parser';
Everything seems to work correctly. Also if i modify the index.d.ts in the json-schema-ref-parser package from
import * as $RefParser from "@apidevtools/json-schema-ref-parser";
export = $RefParser;
to
import $RefParser from "@apidevtools/json-schema-ref-parser";
export = $RefParser;
Everything seems to be happy.
So the CORRECT fix is for the json-schema-ref-parser package to replace it with the code
index.d.ts
export * from "@apidevtools/json-schema-ref-parser"
import $RefParser from "@apidevtools/json-schema-ref-parser"
export default $RefParser
Seems like #171 will fix the constructor issues.
:tada: This issue has been resolved in version 9.0.8 :tada:
The release is available on:
v9.0.8
Your semantic-release bot :package::rocket:
For anybody else that stumbles upon this issue like I did after finding that there is still an issue with the Typescript typings for this library, an acceptable solution that I found is to install @apidevtools/json-schema-ref-parser
instead of the "wrapper" package json-schema-ref-parser
.
Requiring/importing @apidevtools/json-schema-ref-parser
even when you have json-schema-ref-parser
does indeed work to help settle the type issue, but if you use the import/no-extraneous-dependencies
ESLint rule in your projects, installing the scoped package allows the linter and compiler to both be happy.
Code snippet:
Error: