Microsoft/TypeScript

Ghost error in a circular situation

Open

#62,181 建立於 2025年8月3日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: check: Error InstabilityHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 Search Terms

ghost error circular error mapped type

🕗 Version & Regression Information

⏯ Playground Link

No response

💻 Code

/// <reference path="fourslash.ts" />

// @strict: true
// @target: esnext
// @lib: esnext

//// 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/*1*/() {
////     return optional(Category);
////   },
//// });
////
//// export const output = Category.output;

verify.quickInfoAt("1", `(getter) parent: any`);
verify.getSemanticDiagnostics([]);

🙁 Actual behavior

Depending on the presence of verify.quickInfoAt("1", (getter) parent: any); the compiler produces 1 or 2 errors (observable in the expected output of the failing verify.getSemanticDiagnostics([]) assertion).

🙂 Expected behavior

I'd expect the error count to be the same.

Additional information about the issue

Relates to https://github.com/microsoft/TypeScript/issues/62180

An extra test case that currently works OK but that suffered from a similar issue in the past:

/// <reference path="fourslash.ts" />

// @strict: true
// @target: esnext
// @lib: esnext

//// interface ZodType {
////   optional: "true" | "false";
////   output: any;
//// }
////
//// interface ZodString extends ZodType {
////   optional: "false";
////   output: string;
//// }
////
//// 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 {
////   optional: "false";
////   output: InferObjectType<T>;
//// }
////
//// interface ZodOptional<T extends ZodType> extends ZodType {
////   optional: "true";
////   output: T["output"] | undefined;
//// }
////
//// declare function object<T extends ZodShape>(shape: T): ZodObject<T>;
//// declare function string(): ZodString;
//// declare function optional<T extends ZodType>(schema: T): ZodOptional<T>;
////
//// const Category = object({
////   name: string(),
////   get parent/*1*/() {
////     return optional(Category);
////   },
//// });
////
//// export const output = Category.output

verify.quickInfoAt("1", `(getter) parent: ZodOptional<ZodObject<{
    name: ZodString;
    readonly parent: ZodOptional<ZodObject<...>>;
}>>`);
verify.getSemanticDiagnostics([]);

貢獻者指南