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

Typings for Polymer.mixinBehavior() assume a concrete type #5054

Closed
kito99 opened this issue Jan 19, 2018 · 4 comments
Closed

Typings for Polymer.mixinBehavior() assume a concrete type #5054

kito99 opened this issue Jan 19, 2018 · 4 comments

Comments

@kito99
Copy link

kito99 commented Jan 19, 2018

Description

The typings for Polymer.mixinBehavior() do not allow use of abstract classes.

Steps to Reproduce

Example:

class MyappView1 extends Polymer.mixinBehaviors([Polymer['AppLocalizeBehavior']], NowElements.BaseView) {
}

Where NowElements.BaseView is an abstract class that extends Polymer.Element.

Expected Results

Successful compilation and execution.

Actual Results

TypeScript compilation error:

Error:(8, 84) TS2345: Argument of type 'typeof BaseView' is not assignable to parameter of type 'new () => BaseView'.
  Cannot assign an abstract constructor type to a non-abstract constructor type.

Browsers Affected

All

Versions

master

What's a little frustrating about this is that the everything works fine if you change the type declaration to the following:

 function mixinBehaviors(behaviors: object|object[], klass: any): any;

Clearly this is a pretty unsafe type declaration, but since the code runs, it's clear that JavaScript has no problem using an abstract class; it's a TypeScript issue.

I'm not sure there's a good solution for this, given there is a TypeScript limitation: microsoft/TypeScript#5843, but I think it's worth discussion so we can at the very least say something in the docs.

@TimvdLippe
Copy link
Contributor

It appears that the upstream TypeScript issue has been closed as [working as intended]: microsoft/TypeScript#5843 (comment) Not sure how we can resolve this issue.

@TimvdLippe
Copy link
Contributor

Per https://stackoverflow.com/questions/12802317/passing-class-as-parameter-causes-is-not-newable-error I thought typeof T would work here, but sadly that did not work either as it is a generic type 😢

@aomarks aomarks removed their assignment May 1, 2018
@stale
Copy link

stale bot commented Mar 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 13, 2020
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen!

@stale stale bot closed this as completed Apr 17, 2022
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

3 participants