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

未关闭
#64,249 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@weswigham 已经在做这个了。

开始于 2026年9月14日。

评估

这个 Issue 还没有评估数据。

描述

Needs Investigation
🔎 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?;
主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。