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

Could not find declaration file for declarative-event-listeners #76

Open
Lithl opened this issue Nov 30, 2018 · 2 comments
Open

Could not find declaration file for declarative-event-listeners #76

Lithl opened this issue Nov 30, 2018 · 2 comments

Comments

@Lithl
Copy link

Lithl commented Nov 30, 2018

Trying to follow the documentation to make use of @listen, I added import {DeclarativeEventListeners} from '@polymer/decorators/lib/declarative-event-listeners.js'; to the top of my file and my element extends DeclarativeEventListeners(PolymerElement). However, when my typescript is compiled, I get:

node_modules/@polymer/decorators/lib/decorators.d.ts:11:32 - error TS7016: Could not find a declaration file for module '@polymer/polymer/polymer-element.js'. '/path/to/node_modules/@polymer/polymer/polymer-element.js' implicitly has an 'any' type.

11 import { PolymerElement } from '@polymer/polymer/polymer-element.js';
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

path/to/index.ts:3:41 - error TS7016: Could not find a declaration file for module '@polymer/decorators/lib/declarative-event-listeners.js'. '/path/to/node_modules/@polymer/decorators/lib/declarative-event-listeners.js' implicitly has an 'any' type.

3 import {DeclarativeEventListeners} from '@polymer/decorators/lib/declarative-event-listeners.js';
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If I mark the function being decorated as private, I get an additional error:

path/to/index.ts:39:4 - error TS2345: Argument of type 'MyClass' is not assignable to parameter of type 'ElementPrototype & HasEventListener<"myFunction_">'.
  Type 'MyClass' is not assignable to type 'HasEventListener<"myFunction_">'.
    Property 'myFunction_' is private in type 'MyClass' but not in type 'HasEventListener<"myFunction_">'.

39   @listen('select', document)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~

I have no such problem marking a function private and annotating it with @observe or marking a property private and annotating with @query.

@Lithl Lithl changed the title Could not find declaration file for declaration-event-listeners Could not find declaration file for declarative-event-listeners Nov 30, 2018
@aomarks
Copy link
Member

aomarks commented Nov 30, 2018

Hmm, I was not able to reproduce your first error. Are you sure you have @polymer/polymer and @polymer/decorators installed, and that your tsconfig.json is set up correctly to resolve dependencies in node_modules/? Are you able to import PolymerElement or e.g. the customElement decorator in your own module?

As for the second error, @listen decorated properties must, unfortunately, have public visibility. This is documented at https://github.com/Polymer/polymer-decorators#listeneventname-string-target-stringeventtarget. The public visibility requirement exists because the signature for the @listen decorator is designed to enforce at compile time that the function you decorate has the correct signature ((Event) => void), which requires it to have public visibility.

@Lithl
Copy link
Author

Lithl commented Dec 1, 2018

package.json includes:

  "dependencies": {
    "@polymer/polymer": "^3.1.0"
  },
  "devDependencies": {
    "@polymer/decorators": "^3.0.0"
  }

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "baseUrl": ".",
    "rootDir": ".",
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    }
  },
  "include": [
    "src/**/*.ts"
  ]
}

I am successfully importing and using PolymerElement, as well as the customElement, observe, and query decorators.

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