Skip to content
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

class completions include implemented interface's optional attribute #54703

Closed
5 tasks
deepkolos opened this issue Jun 19, 2023 · 1 comment
Closed
5 tasks

Comments

@deepkolos
Copy link

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

@RyanCavanaugh
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants