Skip to content

Implements typeof object does not scaffold missing properties #61556

Open
@YaroslavLisovets

Description

@YaroslavLisovets

🔎 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.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions