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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'value' does not exist on type 'EventTarget' #35293

Closed
sysmat opened this issue Feb 10, 2020 · 3 comments
Closed

Property 'value' does not exist on type 'EventTarget' #35293

sysmat opened this issue Feb 10, 2020 · 3 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler
Milestone

Comments

@sysmat
Copy link

sysmat commented Feb 10, 2020

tsconfig.json:
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictTemplates": true
}

馃殌 feature request

Relevant Package

angular 9

Description

Casting in html template

(keyup)="filter($event.target.value)"

Describe the solution you'd like

(keyup)="filter(($event.target as HTMLInputElement).value)"

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?
@pkozlowski-opensource pkozlowski-opensource added the area: language-service Issues related to Angular's VS Code language service label Feb 10, 2020
@ngbot ngbot bot added this to the needsTriage milestone Feb 10, 2020
@kara kara added area: compiler Issues related to `ngc`, Angular's template compiler comp: ivy and removed area: language-service Issues related to Angular's VS Code language service labels Feb 10, 2020
@alxhub
Copy link
Member

alxhub commented Feb 10, 2020

Hello @sysmat,

Unfortunately casting in templates isn't really possible at this point. There is no way to import types within a template and it's not likely that Angular will gain that ability in the near future.

There are three potential approaches here:

  1. use an explicit cast to any:
<input (keyup)="filter($any($event.target).value)">
  1. Globally tell Angular not to check the type of DOM event bindings by disabling strictDomEventTypes:
{
  "angularCompilerOptions": {
    "strictTemplates": true
    "strictDomEventTypes": false,
  }
}
  1. Use a component method to implement the cast:
@Component({
  selector: '...',
  template: '<input (keyup)="filter(target($event).value)">',
})
export class SomeCmp {
  target(event: KeyboardEvent): HTMLInputElement {
    if (!(event.target instanceof HTMLInputElement)) {
      throw new Error("wrong target");
    }
    return event.target;
  }
}

@alxhub alxhub closed this as completed Feb 10, 2020
@topce
Copy link

topce commented Feb 11, 2020

Hi @sysmat @pkozlowski-opensource and @alxhub

According Angular documentation passing event is a dubious practice:
passing event is a dubious practice.
There they advise to use template ref

Is it documentation still relevant !?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler
Projects
None yet
Development

No branches or pull requests

5 participants