Skip to content

class completions include implemented interface's optional attribute #54703

Description

@deepkolos

Suggestion

interface Type {
  isA?: true;
  isB?: false;
}
class A implements Type {
  isA: true = true;
  a = 1;
}

let a: A;

a.isA
a.isB

🔍 Search Terms

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

class implements interface completions

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

📃 Motivating Example

💻 Use Cases

use case

interface Type {
  isA?: false;
  isB?: false;
}
type PickType<T extends keyof Type> = {
  [K in keyof Type]?: K extends T ? true : false | undefined;
};
class A implements PickType<'isA'> {
  isA: true = true;
  a = 1;
}
class B implements PickType<'isB'> {
  isB: true = true;
  b = 1;
}
type AorB = A | B;
let a: AorB | undefined;
if (a) {
  if (a.isA) a.a; // error Property 'isA' does not exist on type 'B'
  if (a.isB) a.b; // error Property 'isB' does not exist on type 'A'
}

typescriptlang live link

Activity

  1. RyanCavanaugh commented on Jun 19, 2023

    @RyanCavanaugh
    Member

    To expedite the triage process, we need everyone to follow the issue template and instructions.

    When you clicked "Create New Issue", the issue form was pre-populated with a template and some instructions. We need you to read those instructions completely, follow them, and then fill in all the fields in that template.

    We are not able to assist with issues that don't follow the template instructions as they represent a significantly larger amount of work compared to issues which are correctly specified. Thank you for understanding.

  2. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions