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

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

Open
reecefenwick opened this issue Mar 19, 2024 · 0 comments
Open

Comments

@reecefenwick
Copy link

reecefenwick commented Mar 19, 2024

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 },
        ],
      }),
    ),
  ),
);
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

No branches or pull requests

1 participant