Skip to content

Implements typeof object does not scaffold missing properties #61556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YaroslavLisovets opened this issue Apr 9, 2025 · 0 comments · May be fixed by #61559
Open

Implements typeof object does not scaffold missing properties #61556

YaroslavLisovets opened this issue Apr 9, 2025 · 0 comments · May be fixed by #61559
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@YaroslavLisovets
Copy link

🔎 Search Terms

typeof object, implements, missing properties, scaffolding, IDE, VSCode, class implements, autocomplete, schema typing

🕗 Version & Regression Information

  • Tested in TypeScript 5.8.2
  • Behavior consistently observed in VSCode stable and insiders and WebStorm 2024.3.4.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKlC8UDeAoK6oEMBcUB2ArgLYBGEATgNxoYm4DOw5AlngOaVQoC+KKAxgHs8jKMATIa6HFACMAGilQ6UAOSzVPPqEhQAkngBmFCABM4iHREGGx1AQBtM9erADCTl1GZEwDiEQQeMCucKi8js6uBsbkZjAeUd6+-oHB0UYm5pJaKFZQAOrkmGCQphJIAO7FZbgxWTAR-J6uRSVl9eTJfgFBIYU1ZUi8QA

💻 Code

const schema = { a: Number, b: String };
type SchemaType = typeof schema;

class MyClass implements SchemaType {
  // ❌ TypeScript reports missing properties 'a' and 'b'
  // ❌ But VSCode does NOT scaffold them via Quick Fix ("Add missing members")
  // ❌ No autocomplete suggestions either
}

However, if the same structure is wrapped in another object type, scaffolding does work:

type Wrapped = { schema: typeof schema };

class MyWrappedClass implements Wrapped {
  schema = {
    a: Number,
    b: String,
  };
  // ✅ IDE scaffolds 'schema.a' and 'schema.b' as expected
}

Even more interesting: when using a schema-type library like computed-types, class scaffolding does work when implementing Type<typeof Schema(...)> — even though that ultimately derives from an object structure as well.

🙁 Actual behavior

Missing members are reported, but IDE does not scaffold them unless the type is wrapped. This makes working with typeof schemaObject types harder, despite TypeScript fully understanding what’s missing.

🙂 Expected behavior

When implementing a plain object type using typeof, TypeScript tooling (e.g. WebStorm) should provide the same scaffolding as it does with interface-like types or wrapper types. This would improve DX for common schema-driven design patterns.

Additional information about the issue

📌 Notes

  • This issue blocks ergonomic use of typeof for schemas in class-based design patterns (e.g., validation classes or model classes).
  • Possibly related to how typeof resolves to an anonymous object type, which the scaffolder might treat differently from named/interface types.
  • Libraries like computed-types somehow work around this by exposing types via Type that expand the structure enough for tooling to scaffold
  • Inside computed-types sources, the scaffolding doesn't happen either — only when used externally in a consumer project

It would be great if TypeScript + tooling could scaffold missing properties even when using typeof of a plain object in a class implementation — especially since this is a common pattern for schema-based design (validation, form definitions, etc.).

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Apr 9, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants