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

Externals imports possibly broken? #107

Open
matthewchngshopback opened this issue Mar 22, 2022 · 4 comments
Open

Externals imports possibly broken? #107

matthewchngshopback opened this issue Mar 22, 2022 · 4 comments

Comments

@matthewchngshopback
Copy link

matthewchngshopback commented Mar 22, 2022

Context

Using @ovotech/avro-ts-cli@3.4.7 and executing

npx avro-ts address.avsc.json create-user.avsc.json

where both the schemas were copied from avro-ts/examples

Expected

Generated TypeScript files should contain no errors in their imports of external references

Actual

I got these generated output with errors in imports of external reference to my.namespace.data.Address

create-user.avsc.json.ts has

  1. import which wasn't exported from address.avsc.json.ts; and
  2. import is missing alias identifier after the as; and
  3. broken CreateUser.address reference with an undefined namespace.
/* eslint-disable @typescript-eslint/no-namespace */

import { type MyNamespaceDataAddress as  } from "./address.avsc.json";     (1), (2)

export type CreateUser = MyNamespaceMessages.CreateUser;

export namespace MyNamespaceMessages {
    export const CreateUserName = "my.namespace.messages.CreateUser";
    export interface CreateUser {
        userId: string;
        name: string;
        address: MyNamespaceDataAddress.Address;                           (3)
    }
}

address.avsc.json looks ok and the namespace exported is actually MyNamespaceData rather than MyNamespaceDataAddress which is imported by the create-user.avsc.json.ts above.

/* eslint-disable @typescript-eslint/no-namespace */

export type Address = MyNamespaceData.Address;

export namespace MyNamespaceData {
    export const AddressName = "my.namespace.data.Address";
    export interface Address {
        street: string;
        zipcode: string;
        country: string;
    }
}
@cafreeman
Copy link
Contributor

+1 I'm experiencing this same issue.

@rockt987
Copy link

rockt987 commented Jul 19, 2022

Hi, 

I think the main problem come from Typescript breaking change on version 4.5

Base on what I found after I install @ovotech/avro-ts-cli@3.4.10

  • It use @ovotech/avro-ts@6.0.8
  • @ovotech/ts-compose@0.16.0
  • typescript@4.7.4

With @ts-compose@0.16.0 the code where it create import statement specifier is the following

return ts.factory.createImportSpecifier(
       item.as ? exports.Node.Identifier(item.name) : undefined, 
       item.as ? exports.Node.Identifier(item.as) : exports.Node.Identifier(item.name))
})

Once I update the call to the following, the import statement specifier is create correctly



return ts.factory.createImportSpecifier(
       false, 
       item.as ? exports.Node.Identifier(item.name) : undefined, 
       item.as ? exports.Node.Identifier(item.as) : exports.Node.Identifier(item.name))
})


I think the solution is either force typescript version to be 4.1.2
 or upgrade @ts-compose@0.16.0 to version 0.20.0 which already fix API breaking change on typescript 4.5 (https://github.com/ovotech/laminar/blob/d197413e78625b710480de35e99e5d5d9d13a6cc/packages/ts-compose/src/node.ts#L205)

@ivank
Copy link
Contributor

ivank commented Jul 19, 2022

Both are options for sure - if anybody wants to try a PR I would be eternally grateful, don't have much time to fix those issues lately.

@gwer
Copy link

gwer commented Jan 10, 2024

There is a workaround to temporary solve this issue while we wait for dependencies upgrade. Try to force correct version through resolutions in package.json:

  "resolutions": {
    "@ovotech/ts-compose": "^0.20.0"
  }

@gwer gwer mentioned this issue Jan 10, 2024
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

5 participants