castle icon indicating copy to clipboard operation
castle copied to clipboard

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

Open reecefenwick opened this issue 5 months ago • 0 comments

Hey Team,

I've encountered an issue in @ovotech/[email protected] where it doesn't seem to support providing an instance of an Type from the [email protected] 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 },
        ],
      }),
    ),
  ),
);

reecefenwick avatar Mar 19 '24 06:03 reecefenwick