question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Several compilation errors with AJV 8.6.2 and Typescript 4.3.5

See original GitHub issue

Since upgrading to the latest version, tsc can’t compile anymore AJV. As reported by several other users, it seams to be a core problem of the current version. I report this, because my output is different from the others but the core problem seams to be a incompatibility with typescript.

What version of Ajv are you using? 8.6.2

What results did you expect? that the lib can be compiled with tsc

Are you going to resolve the issue? No but I hope you can reproduce and fix it.

tsc -v
Version 4.3.5

//same result with or without --noEmit option
tsc --project tsconfig.build.json --noEmit
node_modules/ajv/lib/compile/codegen/code.ts:52:5 - error TS2322: Type 'CodeItem' is not assignable to type 'string'.

52     return (this._str ??= this._items.reduce((s: string, c: CodeItem) => `${s}${c}`, ""))
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ajv/lib/compile/codegen/code.ts:52:13 - error TS2322: Type 'CodeItem' is not assignable to type 'string'.
  Type 'number' is not assignable to type 'string'.

52     return (this._str ??= this._items.reduce((s: string, c: CodeItem) => `${s}${c}`, ""))
               ~~~~~~~~~

node_modules/ajv/lib/compile/codegen/code.ts:139:3 - error TS2322: Type 'string | number | boolean | string[]' is not assignable to type 'string | SafeExpr'.
  Type 'string[]' is not assignable to type 'string | SafeExpr'.
    Type 'string[]' is not assignable to type 'string'.

139   return typeof x == "number" || typeof x == "boolean" || x === null
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140     ? x
    ~~~~~~~
141     : safeStringify(Array.isArray(x) ? x.join(",") : x)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ajv/lib/core.ts:356:3 - error TS2394: This overload signature is not compatible with its implementation signature.

356   compile<T = unknown>(schema: Schema | JSONSchemaType<T>, _meta?: boolean): ValidateFunction<T>
      ~~~~~~~

  node_modules/ajv/lib/core.ts:368:3
    368   compile<T = unknown>(schema: AnySchema, _meta?: boolean): AnyValidateFunction<T> {
          ~~~~~~~
    The implementation signature is declared here.

node_modules/ajv/lib/core.ts:377:3 - error TS2394: This overload signature is not compatible with its implementation signature.

377   compileAsync<T = unknown>(
      ~~~~~~~~~~~~

  node_modules/ajv/lib/core.ts:390:3
    390   compileAsync<T = unknown>(
          ~~~~~~~~~~~~
    The implementation signature is declared here.


Found 5 errors.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Celbinecommented, Sep 9, 2021

I also had this problem and it was in the import line

import ... from "ajv/lib/types/index";

Perhaps you have a similar import line somewhere, it should be replaced with

import ... from "ajv";

1reaction
YukiGibsoncommented, Jul 15, 2022

Had the same issue, was importing SchemaObject as

import {SchemaObject} from ‘ajv/lib/types’;

But it was exposed at the top level, so issue resolved

import {SchemaObject} from ‘ajv’;

Read more comments on GitHub >

github_iconTop Results From Across the Web

ajv - NPM Package Overview - Socket.dev
Start using Socket to analyze ajv and its 4 dependencies to ... of referenced schemas during compilation; "All errors" validation mode with ...
Read more >
ajv-errors - Ajv JSON schema validator
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Read more >
Ajv NPM | npm.io
Check Ajv 8.10.0 package - Last release 8.10.0 with MIT licence at our NPM ... during compilation; "All errors" validation mode with option...
Read more >
第三方软件和许可证 - JetBrains
软件 授权许可 版本 .babelrc JSON Schema (.babelrc‑schema.json) Apache 2.0 JSON schema for Babel 6+ con... .eslintrc JSON Schema (.eslintrc‑schema.json) Apache 2.0 JSON schema for ESLint...
Read more >
How to make oneOf field nullable with typescript and ajv
It doesn't compile as typescript thinks it's trying to assign an optional type to a non-optional type. The problem arises since you are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found