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

Why do we have to copy the members of interface to class definitions? #42

Closed
e-cloud opened this issue May 26, 2018 · 4 comments
Closed

Comments

@e-cloud
Copy link
Contributor

e-cloud commented May 26, 2018

see

private _resolveInterfaceMembers(docs: TDoclet[]) {

a reasonable version

// jsdoc marked as mixin
interface A {
	a(): void;
}

// jsdoc marked as interface
interface B {
	b(): void;
}

class C implements A, B {
}

current output

// jsdoc marked as mixin
interface A {
	a(): void;
}

// jsdoc marked as interface
interface B {
	b(): void;
}

class C implements A, B {
	static a(): void;
	b(): void;
}

The reason of static occurrence is because in jsdoc mixins do not apply scope: instance.

I can not figure out why should we copy those members to class. IMO, it's unnecessary.

@englercj
Copy link
Owner

englercj commented May 28, 2018

Because the first thing you listed is invalid Typescript.

Class 'C' incorrectly implements interface 'A'.
  Property 'a' is missing in type 'C'.
Class 'C' incorrectly implements interface 'B'.
  Property 'b' is missing in type 'C'.

A class that implements an interface must define the items it implements.

@e-cloud
Copy link
Contributor Author

e-cloud commented May 28, 2018

Emmmmm, @englercj you are right. We may achieve the same goal via simpler solution. See microsoft/TypeScript#340 (comment)

@englercj
Copy link
Owner

Seems reasonable, happy to merge a PR that uses namespace merging instead of copying members.

@englercj
Copy link
Owner

v2 was just released and after the rewrite I used this namespace merging technique for classes that implement interfaces.

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

No branches or pull requests

2 participants