Skip to content

[BUG]: infer as Infer from Zod gets rewritten to use Typescript's infer #764

@jamietanna

Description

@jamietanna

Reproduction link or steps

https://github.com/JamieTanna-Mend-testing/tsdown-zod-infer

What is expected?

Given the code:

// or similar, when built
import type { infer as Infer } from 'zod';
import { ZodType } from 'zod';

When building a .d.ts, we should see the same import rewrite

What is actually happening?

import { infer, z } from "zod"; // 1. typescript: 'infer' is declared but its value is never read. [6133]

//#region src/index.d.ts
declare const productSchema: z.ZodObject<{
  id: z.ZodString;
  price: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
  id: string;
  price: number;
}, {
  id: string;
  price: number;
}>;
declare function printItem<T>(item: T): void;
declare const product: infer<typeof productSchema>; // 1. typescript: Identifier expected. [1003]
declare const c: void;
//#endregion
export { c, printItem, product, productSchema };
//# sourceMappingURL=index.d.ts.map

Which results in code that cannot be imported, as the infer Typescript built-in is used, instead of the one from Zod

Any additional comments?

Moved from rolldown/rolldown#8259

Part of renovatebot/renovate#41038

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdts

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions