castle
castle copied to clipboard
Externals imports possibly broken?
Context
Using @ovotech/[email protected]
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
-
import
which wasn't exported fromaddress.avsc.json.ts
; and -
import
is missing alias identifier after theas
; and - 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;
}
}
+1 I'm experiencing this same issue.
Hi, I think the main problem come from Typescript breaking change on version 4.5
Base on what I found after I install @ovotech/[email protected]
- It use @ovotech/[email protected]
- @ovotech/[email protected]
- [email protected]
With @[email protected] 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 @[email protected] 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)
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.
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"
}