microsoft / microsoft/TypeScript

Confusing missing property error in a circular situation

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

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

2026年9月18日 から。

Domain: Mapped Types Help Wanted Possible Improvement
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

🔎 Search Terms

missing property mapped type getter deferred

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250802#code/JYOwLgpgTgZghgYwgAgFoHsAmAVAngBwgB5sA+ZAbwChll18xh0Q4AbALmQCIwoBXCF2QAfbvFYBnQQG4adPmHwLO2WQF8qVUJFiIUGTAGVeoAObIIAD0ghMEtFjyEiEkyFPlqteo2ZtOXOJSXOqaYAT6WIYAFnCEyAC8yABKEAjoUJgubqYANMhwILiksuHxAApQEGCMMLgk5EkUyADaANLIoMgA1hC46DDI2AC6Ku3DyGrIAGSUaqURyACSIDDQAPIARgBWaWBOxDFxKFY2dg5GsYSNyJXVtfVyXrSt3Z0gPX0DyEfxcPa-CAtboTU4QWz2Zo+JgsDjcXgCIQaF4vAD8PTkKM4IAgADdoMNUZxAcDhi0uOgFEowFxhrJaFNZs9aMD3p9+oNAQUAVcgSCLNZwecoQwYf54fxBJNMWjkDj8VAZbROCDibzSeTKYoFLT6dKSlpwNB4EgLltdggwCQBWd7AZAeQwRCLgciCs1lBzXtXWRPHJoX44YE2MFQoadCbIph1qLA9anecDK7CsVSHIE3bHBESJqqTqJqI+LYIDBQBBMH7vLHYQEETIqBoqJg0qw4FVkDAi5aYXQdnt44LnfbeaQABQSXkqACUnAMXstDVkzYQrfbnZA3eYyFcUDMo5nF2Mu-cS5bbZQ683HwDsIHtpd2ZTpDHEgQ0QgAFs4NPZ1gY75bzIWQqHSEBXGQABhOBIFMDJcESXsLTAUdnhYD8IE4Hc9ynXI5FMapkHwc9wH3SgZSqMA+Cga9qzYUcoJguCpz1NRcLUZjNCsfAMjAZBQPArVqQQhiIFgqBcAAOkEhRZCAA

💻 Code
interface ZodType<T> {
  optional: "true" | "false";
  output: T;
}

interface ZodString extends ZodType<string> {
  optional: "false";
}

type ZodShape = Record<string, any>;
type Prettify<T> = { [K in keyof T]: T[K] } & {};
type InferObjectType<Shape extends ZodShape> = Prettify<
  {
    [k in keyof Shape as Shape[k] extends { optional: "true" }
      ? k
      : never]?: Shape[k]["output"];
  } & {
    [k in keyof Shape as Shape[k] extends { optional: "true" }
      ? never
      : k]: Shape[k]["output"];
  }
>;
interface ZodObject<T extends ZodShape> extends ZodType<InferObjectType<T>> {
  optional: "false";
}

interface ZodOptional<T extends ZodType<any>>
  extends ZodType<T["output"] | undefined> {
  optional: "true";
}

declare function object<T extends ZodShape>(shape: T): ZodObject<T>;
declare function string(): ZodString;
declare function optional<T extends ZodType<any>>(schema: T): ZodOptional<T>;

const Category = object({
  name: string(),
  get parent() {
    // Argument of type 'ZodObject<{ name: ZodString; readonly parent: ZodOptional<ZodType<any>>; }>' is not assignable to parameter of type 'ZodType<any>'.
    //   Property 'output' is missing in type 'ZodObject<{ name: ZodString; readonly parent: ZodOptional<ZodType<any>>; }>' but required in type 'ZodType<any>'.(2345)
    return optional(Category);
  },
});

export const output = Category.output;
🙁 Actual behavior

A very confusing error is produced here. A ZodObject extends ZodType and that has an output property so how it can be missing?

🙂 Expected behavior

I don't expect to see this error

Additional information about the issue

Note that if we remove export const output = Category.output; then we can see a new error appearing:

'parent' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.(7023)

And this one makes sense (but I'd argue the other one shouldn't appear at all in this scenario).

This has changed with https://github.com/microsoft/TypeScript/pull/58337 , before this PR the circularity error was present with and without export const output = Category.output;

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

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

はじめの一歩

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

評価

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

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

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