microsoft / microsoft/TypeScript

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

オープン
#64,249 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@weswigham がすでに取り組んでいます。

2026年9月14日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔎 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

```ts
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:
```ts
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`:

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。