microsoft / microsoft/TypeScript
Ghost error in a circular situation
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 Search Terms
ghost error circular error mapped type
### 🕗 Version & Regression Information
- This changed in commit or PR https://github.com/microsoft/TypeScript/pull/58337
### ⏯ Playground Link
_No response_
### 💻 Code
```ts
///
// @strict: true
// @target: esnext
// @lib: esnext
//// interface ZodType {
//// optional: "true" | "false";
//// output: T;
//// }
////
//// interface ZodString extends ZodType {
//// optional: "false";
//// }
////
//// type ZodShape = Record;
//// type Prettify = { [K in keyof T]: T[K] } & {};
//// type InferObjectType = 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 extends ZodType> {
//// optional: "false";
//// }
////
//// interface ZodOptional>
//// extends ZodType {
//// optional: "true";
//// }
////
//// declare function object(shape: T): ZodObject;
//// declare function string(): ZodString;
//// declare function optional>(schema: T): ZodOptional;
////
//// 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
```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;
//// type Prettify = { [K in keyof T]: T[K] } & {};
//// type InferObjectType = 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 extends ZodType {
//// optional: "false";
//// output: InferObjectType;
//// }
////
//// interface ZodOptional extends ZodType {
//// optional: "true";
//// output: T["output"] | undefined;
//// }
////
//// declare function object(shape: T): ZodObject;
//// declare function string(): ZodString;
//// declare function optional(schema: T): ZodOptional;
////
//// const Category = object({
//// name: string(),
//// get parent/*1*/() {
//// return optional(Category);
//// },
//// });
////
//// export const output = Category.output
verify.quickInfoAt("1", `(getter) parent: ZodOptional>;
}>>`);
verify.getSemanticDiagnostics([]);
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the embedded fourslash.ts repro and compare diagnostics with and without verify.quickInfoAt("1", `(getter) parent: any`). Trace the circular mapped-type case introduced by PR 58337, using the failing verify.getSemanticDiagnostics([]) assertion as the check. Done means both variants produce the same error count while the reported quick info remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100