mtth / avsc

Avro for JavaScript :zap:
MIT License
1.27k stars 147 forks source link

Schema from registry not type compatible with `forSchema` #400

Closed jcjp closed 2 years ago

jcjp commented 2 years ago

Here is what I have in my code:

public async setup() {
  const id = await this.registry.getLatestSchemaId(this.subject)
  const schema = await this.registry.getSchema(id)
  this.service= avro.Type.forSchema(schema)
}

Using the library @kafkajs/confluent-schema-registry to get the schema from the registry then passing it to the forSchema returns a type error of:

Argument of type 'Schema | AvroSchema' is not assignable to parameter of type 'Schema'.
  Type 'import("<project_dir>/node_modules/@kafkajs/confluent-schema-registry/dist/@types").Schema' is not assignable to type 'import("<project_dir>/node_modules/avsc/types/index").Schema'.
  Type 'Schema' is not assignable to type 'FixedType & LogicalTypeExtension'.
  Type 'Schema' is missing the following properties from type 'FixedType': type, name,
  sizets(2345)

I can mitigate this type error by setting the schema as any like thits:

public async setup() {
  const id = await this.registry.getLatestSchemaId(this.subject)
  const schema: any = await this.registry.getSchema(id)
  this.service= avro.Type.forSchema(schema)
}
mtth commented 2 years ago

Hi @jcjp. This particular issue sounds best addressed in @kafkajs/confluent-schema-registry - avsc doesn't have control over types declared in dependent libraries. (It is true that the typings in this repository are WIP though, please feel free to reopen for avsc-specific improvements.)