Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: custom ajv instance fails with type error #236

Open
pwmcintyre opened this issue Mar 22, 2023 · 2 comments · May be fixed by #254
Open

bug: custom ajv instance fails with type error #236

pwmcintyre opened this issue Mar 22, 2023 · 2 comments · May be fixed by #254

Comments

@pwmcintyre
Copy link

pwmcintyre commented Mar 22, 2023

the docs say you can specify a customer Ajv instance to handle custom formats and what not, but i'm getting a type failure

docs:

Alternatively, you can provide a custom Ajv instance using the `ajvInstance` option. This can be useful if you
need to configure Ajv outside of what the constructor parameters allow.
```ts
const options = {
[SchemaType.JSON]: {
ajvInstance: new Ajv()
}
}
```

however this code:

import { SchemaRegistry } from '@kafkajs/confluent-schema-registry'
import Ajv from 'ajv'
const registry = new SchemaRegistry({ host: process.env.KAFKA_BROKER_URL! }, {
    JSON: {
        ajvInstance: new Ajv(),
    }
})

yields:

Argument of type '{ JSON: { ajvInstance: Ajv; }; }' is not assignable to parameter of type 'SchemaRegistryAPIClientOptions | undefined'.
  Types of property 'JSON' are incompatible.
    Type '{ ajvInstance: Ajv; }' is not assignable to type 'CurrentOptions & DeprecatedOptions & { ajvInstance?: { addSchema: (schema: AnySchema | AnySchema[], key?: string | undefined, _meta?: boolean | undefined, _validateSchema?: boolean | ... 1 more ... | undefined) => Ajv; compile: (schema: any) => ValidateFunction; } | undefined; referencedSchemas?: JsonConfluentSchema...'.
      Type '{ ajvInstance: Ajv; }' is not assignable to type '{ ajvInstance?: { addSchema: (schema: AnySchema | AnySchema[], key?: string | undefined, _meta?: boolean | undefined, _validateSchema?: boolean | "log" | undefined) => Ajv; compile: (schema: any) => ValidateFunction; } | undefined; referencedSchemas?: JsonConfluentSchema[] | undefined; }'.
        The types of 'ajvInstance.addSchema(...).opts' are incompatible between these types.
          Type 'import("/home/peter/seau/git/example/app/node_modules/ajv/dist/core").InstanceOptions' is not assignable to type 'import("/home/peter/seau/git/example/app/node_modules/@kafkajs/confluent-schema-registry/node_modules/ajv/dist/core").InstanceOptions'.
            Type 'InstanceOptions' is not assignable to type 'CurrentOptions'.
              Types of property 'keywords' are incompatible.
                Type 'import("/home/peter/seau/git/example/app/node_modules/ajv/dist/types/index").Vocabulary | undefined' is not assignable to type 'import("/home/peter/seau/git/example/app/node_modules/@kafkajs/confluent-schema-registry/node_modules/ajv/dist/types/index").Vocabulary | undefined'.
                  Type 'Vocabulary' is not assignable to type '(string | KeywordDefinition)[]'.
                    Type 'string | import("/home/peter/seau/git/example/app/node_modules/ajv/dist/types/index").KeywordDefinition' is not assignable to type 'string | import("/home/peter/seau/git/example/app/node_modules/@kafkajs/confluent-schema-registry/node_modules/ajv/dist/types/index").KeywordDefinition'.
                      Type 'CodeKeywordDefinition' is not assignable to type 'string | KeywordDefinition'.
                        Type 'import("/home/peter/seau/git/example/app/node_modules/ajv/dist/types/index").CodeKeywordDefinition' is not assignable to type 'import("/home/peter/seau/git/example/app/node_modules/@kafkajs/confluent-schema-registry/node_modules/ajv/dist/types/index").CodeKeywordDefinition'.
                          Types of property 'code' are incompatible.
                            Type '(cxt: import("/home/peter/seau/git/example/app/node_modules/ajv/dist/compile/validate/index").KeywordCxt, ruleType?: string | undefined) => void' is not assignable to type '(cxt: import("/home/peter/seau/git/example/app/node_modules/@kafkajs/confluent-schema-registry/node_modules/ajv/dist/compile/context").default, ruleType?: string | undefined) => void'.
                              Types of parameters 'cxt' and 'cxt' are incompatible.
                                Type 'KeywordCxt' is missing the following properties from type 'KeywordCxt': failResult, _errorts(2345)

other details

$ node --version               
v18.15.0

package

"@kafkajs/confluent-schema-registry": "^3.3.0",
"ajv": "^8.12.0",
"typescript": "^4.9.5"
@PrestonGiorgianni
Copy link

@pwmcintyre were you able to work around this issue. If so could you post your solution here?

@pgior001 pgior001 linked a pull request Oct 31, 2023 that will close this issue
@pwmcintyre
Copy link
Author

sorry for the late response @PrestonGiorgianni, but I got this working by setting the exact same version of the Ajv package as the one specified by the schema registry package.json

for example, here's a snippet of my package.json

  "dependencies": {
    ...
    "@kafkajs/confluent-schema-registry": "^3.3.0",
    "ajv": "^7.2.4",
    "ajv-formats": "1.5",
    ...
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants