microsoft / microsoft/TypeScript

Ghost error in a circular situation

未关闭
#62,181 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: check: Error Instability Help Wanted
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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

an extra test case
/// <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([]);

贡献指南

打开贡献指南

从这里开始

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

调研方向

从嵌入的 fourslash.ts repro 开始,比较有无 verify.quickInfoAt("1", (getter) parent: any) 时的诊断结果。跟踪 PR 58337 引入的循环 mapped type 情况,并使用失败的 verify.getSemanticDiagnostics([]) 断言作为检查。完成的标准是两个变体产生相同的错误数量,同时报告的 quick info 仍然正确。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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