microsoft / microsoft/TypeScript

Spurious TS4094 "exported anonymous class type may not be private" error after upgrading from TS6 to TS7

Đang mở
#64,249 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@weswigham đang làm issue này rồi.

Từ ngày 14/9/2026.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

🔎 Search Terms

TS4094, exported anonymous class, private, declaration

🕗 Version & Regression Information
  • This changed between versions 6.0.3 and 7.0.2
⏯ Playground Link

https://github.com/jedwards1211/ts-4094-regression

💻 Code
import ZodRoute from "zod-route-schemas";
import z from "zod";

export const organization = new ZodRoute(
  "/org/:organizationId",
  z.object({ organizationId: z.number() }),
);
🙁 Actual behavior
> tsc

src/index.ts:4:14 - error TS4094: Property 'parts' of exported anonymous class type may not be private or protected.

4 export const organization = new ZodRoute(
               ~~~~~~~~~~~~

  src/index.ts:4:14 - Add a type annotation to the variable organization.
    4 export const organization = new ZodRoute(
                   ~~~~~~~~~~~~

src/index.ts:4:14 - error TS4094: Property 'typeHints' of exported anonymous class type may not be private or protected.

4 export const organization = new ZodRoute(
               ~~~~~~~~~~~~

  src/index.ts:4:14 - Add a type annotation to the variable organization.
    4 export const organization = new ZodRoute(
                   ~~~~~~~~~~~~

I don't see what the problem is here, because as you can see below, the generated .d.ts would have the private field types from the class declaration in zod-route-schemas.

🙂 Expected behavior

Outputs the following .d.ts like TS5/6:

import ZodRoute from "zod-route-schemas";
import z from "zod";
export declare const organization: ZodRoute<"/org/:organizationId", z.ZodObject<{
    organizationId: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
    organizationId: number;
}, {
    organizationId: number;
}>, z.ZodType<{
    organizationId: number;
}, any, {
    organizationId: number;
}>, z.ZodType<{
    organizationId: number;
}, any, {
    organizationId: number;
}>>;
//# sourceMappingURL=index.d.ts.map
Additional information about the issue

Doesn't happen with "module": "preserve", but happens with "commonjs", "nodenext", maybe others

ZodRoute declaration in zod-route-schemas/index.d.ts:

declare class ZodRoute<Pattern extends string, Schema extends SchemaForPattern<Pattern>, FormatSchema extends InvertSchema<Schema> = InvertSchema<Schema>, PartialFormatSchema extends PartialSchema<FormatSchema> = PartialSchema<FormatSchema>> {
  readonly pattern: Pattern;
  readonly schema: Schema;
  private parts;
  readonly formatSchema: FormatSchema;
  readonly partialFormatSchema: PartialFormatSchema;
  readonly exact: boolean;
  private typeHints?;

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.