Skip to content

@ovotech/avro-ts - Does not support avsc.Type - "Cannot work out type" #156

@reecefenwick

Description

@reecefenwick

Hey Team,

I've encountered an issue in @ovotech/avro-ts@6.2.0 where it doesn't seem to support providing an instance of an Type from the avsc@5.7.7 library

Here is a minimal reproduction, I would expect the below to work based on the signature of toTypeScript

const x = toTypeScript(
  avro.Type.forSchema({
    type: 'record',
    name: 'ExampleEvent',
    fields: [
      { name: 'id', type: 'string' },
      { name: 'mobile', type: ['null', 'int'], default: null },
      { name: 'name', type: ['null', 'string'], default: null },
    ],
  }),
);

I do have a workaround which is just to convert my avro schema to JSON then parse back to a plain ol JS object

const ts = toTypeScript(
  JSON.parse(
    JSON.stringify(
      avro.Type.forSchema({
        type: 'record',
        name: 'ExampleEvent',
        fields: [
          { name: 'id', type: 'string' },
          { name: 'mobile', type: ['null', 'int'], default: null },
          { name: 'name', type: ['null', 'string'], default: null },
        ],
      }),
    ),
  ),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions