Skip to content

Unable to infer type to extend protected function for mixins #13924

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

Closed
agubler opened this issue Feb 7, 2017 · 0 comments · Fixed by #13990
Closed

Unable to infer type to extend protected function for mixins #13924

agubler opened this issue Feb 7, 2017 · 0 comments · Fixed by #13990
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@agubler
Copy link

agubler commented Feb 7, 2017

TypeScript Version: RC (2.2.0)

Code

class Person {
	constructor(public name: string) {}

	protected myProtectedFunction() {
		// do something
	}
}

type Constructor<T> = new(...args: any[]) => T;

function PersonMixin<T extends Constructor<Person>>(Base: T) {
	return class extends Base {
		constructor(...args: any[]) {
			super(...args);
		}

		myProtectedFunction() {
			super.myProtectedFunction();
			// do more things
		}
	};
}

class Customer extends PersonMixin(Person) {
	accountBalance: number;
}

Expected behavior:

No compilation errors

Actual behavior:

Errors with:

src/test.ts|24 col 7 error| Class 'Customer' incorrectly extends base class 'PersonMixin<typeof Person>.(Anonymous class) & Person'. Type 'Customer' is not assignable to type 'Person'. Property 'myProtectedFunction' is protected but type 'Customer' is not a class derived from 'Person'.

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Feb 9, 2017
@ahejlsberg ahejlsberg self-assigned this Feb 9, 2017
@ahejlsberg ahejlsberg added this to the TypeScript 2.2.1 milestone Feb 9, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 10, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants