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

Access to this.location: Property 'location' does not exist #404

Open
abdonrd opened this issue Oct 21, 2019 · 6 comments
Open

Access to this.location: Property 'location' does not exist #404

abdonrd opened this issue Oct 21, 2019 · 6 comments
Labels
bug Something isn't working DX

Comments

@abdonrd
Copy link
Contributor

abdonrd commented Oct 21, 2019

The docs says that we can access to this.location to get the route parameters:
https://vaadin.github.io/vaadin-router/vaadin-router/#/classes/Router/demos/demo/index.html

And it works.

But when using TypeScript, I get an error:

Property 'location' does not exist

Screenshot 2019-10-21 at 18 14 09

@vlukashov vlukashov added bug Something isn't working DX labels Oct 21, 2019
@vlukashov
Copy link

Looks like an interface or a mixin is missing that would make all router-added properties and callbacks known to TypeScript.

What do you think of a syntax like below?

class PageHome extends RouterView(LitElement) {
  ...
}

@abdonrd
Copy link
Contributor Author

abdonrd commented Oct 21, 2019

Makes sense!

@abdonrd
Copy link
Contributor Author

abdonrd commented Nov 15, 2019

Any news here? Thanks in advance! 😄

@ruanxianzhi
Copy link

Having this problem too, any update?

@platosha
Copy link
Contributor

Hi everybody, here is a PR that adds View TypeScript mixin class together Lifecycle interface: #426

with this change, for using this.location you would have to merge your class with Router.View:

import {Router} from '@vaadin/router';

class MyView extends HTMLElement {
  connectedCallback() {
    this.location;
  }
}
interface MyView extends Router.View {}

Also, inline casting could be used if merging is not desired:

import {Router} from '@vaadin/router';

class MyView extends HTMLElement {
  connectedCallback() {
    (this as Router.View).location;
  }
}

Mind that accessing this.location early before Vaadin Router sets it for the component (for instance in constructor) results in undefined. With Polymer and LitElement, though, it should work with their typical updates and rendering timing, this.location should be available by the time when first connectedCallback does initial update and rendering, for instance.

@platosha
Copy link
Contributor

I have also considered a mixin function like so:

class PageHome extends RouterView(LitElement) {
  ...
}

the thing is, this compiles the function call to JS, so it requires the implementation. We could a trivial one, but I doubt that it brings any value to have this in runtime:

export const RouterView = (superClass) => superClass;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working DX
Projects
None yet
Development

No branches or pull requests

4 participants