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

Type issues with Polymer 3.0.5 and legacy elements #5350

Closed
a-xin opened this issue Aug 31, 2018 · 1 comment
Closed

Type issues with Polymer 3.0.5 and legacy elements #5350

a-xin opened this issue Aug 31, 2018 · 1 comment

Comments

@a-xin
Copy link
Contributor

a-xin commented Aug 31, 2018

I am having issues with the types for legacy elements:

Steps to reproduce

Declare a legacy polymer element via TypeScript:

import { Polymer, html } from '@polymer/polymer/polymer-legacy';

Polymer({
  _template: html`<span>hello</span>`,
  is: 'hello-element',
});

Expected Results

There are no type errors.

Actual Results

The element renders fine but the following type error is shown:
Object literal may only specify known properties, but '_template' does not exist in type 'PolymerInit'. Did you mean to write 'template'?

Versions

  • Polymer: v3.0.5
  • TypeScript: v3.0.1
@a-xin
Copy link
Contributor Author

a-xin commented Sep 14, 2018

Looks like changing the interface as follows solves the typing issues:

export interface PolymerInit {
  is: string;
  extends?: string;
  properties?: PolymerElementProperties;
  observers?: string[];
  _template?: string;
  hostAttributes?: {[key: string]: any};
  listeners?: {[key: string]: string};

  // TODO: What are the allowed keys for behaviors?
  behaviors?: Pick<PolymerInit, Exclude<keyof PolymerInit, 'is' | 'extends' | '_template'>>[];

  // Lifecycle methods
  registered?();
  created?();
  attached?();
  detached?();
  ready?();
  attributeChanged?(name: string, type);

  // Allow any other user-defined properties
  [others: string]: any;
}

Not sure if this is the right way to do it - happy to provide a PR for this.

Reference: https://github.com/Polymer/polymer/blob/master/interfaces.d.ts

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

1 participant