microsoft / microsoft/TypeScript
Confusing missing property error in a circular situation
@ahejlsberg 已经在做这个了。
开始于 2026年9月18日。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 Search Terms
missing property mapped type getter deferred
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 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;
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。