fabien0102 / ts-to-zod

Generate zod schemas from typescript types/interfaces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to generate type alias containing an array of another type

mnbf9rca opened this issue · comments

Bug description

unable to generate array type

Input

export namespace TfLResponse {

  export interface StopPoint {
    naptanId: string;
    // some other stuff
    }

  export interface StopPointArray extends Array<StopPoint> {}

}

i also tried the following but get the same error:

export namespace TfLResponse {

  export interface StopPoint {
    naptanId: string;
    // some other stuff
    }

  export type StopPointArray = StopPoint[];
}

Expected output

i expect the type to be generated:

export const tfLResponseStopPointSchema = z.object({
  naptanId: z.string(),
  // some other stuff
});
export const tfLResponseStopPointArraySchema = z.array(tfLResponseStopPointSchema);

Actual output

zod is giving me this warning, and the StopPointArray type is not being converted:

DeprecationWarning: 'updateInterfaceDeclaration' 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: 'updateTypeAliasDeclaration' 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.
 ›   Warning: Some schemas can't be generated due to direct or indirect missing dependencies:
 ›   tfLResponseStopPointArraySchema
⠋ Validating generated typesDeprecationWarning: '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.
✔ Validating generated types
🎉 Zod schemas generated!

Versions

  • Typescript: v5.1.6
  • Zod: v3.21.4

Interesting, this version is working:

export namespace TfLResponse {
  export interface StopPoint {
    naptanId: string;
    // some other stuff
  }

  export type StopPointArray = Array<StopPoint>;
}

Thanks for the issue!

export interface StopPoint {
  naptanId: string;
  // some other stuff
}

export type StopPointArray = StopPoint[];

This one is also working, so probably an issue around array + namespace

thanks for figuring something out :)

Also ran into this issue.
namespace -> SomeType[] 🔴
namespace -> Array<SomeType> 🟢