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

Incorrect Import Statement and Type Declaration in External Example #157

Open
meirkeller opened this issue Mar 19, 2024 · 4 comments
Open

Comments

@meirkeller
Copy link

meirkeller commented Mar 19, 2024

I'm currently working with the external example in the repository.

Upon executing the script, I encountered the following output:

DeprecationWarning: 'createPropertySignature' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createTypeAliasDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createModuleDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createImportClause' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createImportDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.

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

import { type MyNamespaceDataAddress as  } from "./external-Address";

export type CreateUser = MyNamespaceMessages.CreateUser;

export namespace MyNamespaceMessages {
    export const CreateUserSchema = "{\"type\":\"record\",\"name\":\"CreateUser\",\"namespace\":\"my.namespace.messages\",\"fields\":[{\"name\":\"userId\",\"type\":\"string\",\"logicalType\":\"uuid\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"my.namespace.data.Address\"}]}";
    export const CreateUserName = "my.namespace.messages.CreateUser";
    export interface CreateUser {
        userId: string;
        name: string;
        address: MyNamespaceDataAddress.Address;
    }
}

There are two issues identified in the output:

  1. The import statement import { type MyNamespaceDataAddress as } from "./external-Address"; is incorrect and should be replaced with import { type MyNamespaceData } from "./external-Address";.
  2. The type of address in the CreateUser interface is declared as MyNamespaceDataAddress.Address, but it should be MyNamespaceData.Address.
/* eslint-disable @typescript-eslint/no-namespace */

import { type MyNamespaceData } from "./external-Address";

export type CreateUser = MyNamespaceMessages.CreateUser;

export namespace MyNamespaceMessages {
    export const CreateUserSchema = "{\"type\":\"record\",\"name\":\"CreateUser\",\"namespace\":\"my.namespace.messages\",\"fields\":[{\"name\":\"userId\",\"type\":\"string\",\"logicalType\":\"uuid\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"my.namespace.data.Address\"}]}";
    export const CreateUserName = "my.namespace.messages.CreateUser";
    export interface CreateUser {
        userId: string;
        name: string;
        address: MyNamespaceData.Address;
    }
}

These corrections would ensure the code functions as intended.

Node version: v18.19.0
Typescript version: 5.4.2
Using default tsconfig

@meirkeller
Copy link
Author

Reproduction Steps for the First Issue:

To reproduce the first issue regarding the incorrect import statement, follow these steps:

import { Node, printNode } from '@ovotech/ts-compose';

// Debugging the issue: These args represent the parameters passed down to the import function call
const args = {
    allAs: undefined,
    defaultAs: undefined,
    module: './external-Address',
    named: [
    {
      name: "MyNamespaceData",
      as: "MyNamespaceDataAddress",
    },
  ]
};

console.log(printNode(Node.Import(args)));

Expected output:

import { type MyNamespaceData as MyNamespaceDataAddress } from "./external-Address";

However, you will observe the following output along with deprecation warnings:

DeprecationWarning: 'createImportClause' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createImportDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
import { type MyNamespaceDataAddress as  } from "./external-Address";

@orpilosof21
Copy link

Hi :) I've downgraded the package to version 5.1.0, and it seems to work fine.

@meirkeller
Copy link
Author

@orpilosof21 Thanks!

@elias-thok
Copy link

elias-thok commented Apr 14, 2024

Hi!
I face the same issue but with the avro-ts-cli:

DeprecationWarning: 'createPropertySignature' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createParameterDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
import { type XtypeSnow_syncSnow_record_xusEventExternalV1DataUsRusBaseV1 as  } from "./us_rus_base.avsc";

Node version: v18.16.1
Typescript version: 5.3.3
@ovotech/avro-ts-cli: 3.6.0

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

3 participants