Property 'innerText' does not exist on type 'Element'

Scruffy

I'm using Typescript for Puppeteer. I'm trying to get innerText from an element.

const data = await page.$eval(selector, node => node.innerText);

I'm getting the error:

Property 'innerText' does not exist on type 'Element'

I tried casting to HTMLElement like described in this question: error " Property 'innerText' does not exist on type 'EventTarget' "?

const data = await page.$eval(selector, <HTMLElement>(node: HTMLElement) => node.innerText);

As well as creating my own Interface like this:

interface TextElement extends Element {
    innerText: string;
}

But in each case I'm getting the error that innerText does not exist on this particular type.

Property 'innerText' does not exist on type 'HTMLElement'

Why is this happening and how to deal with this?

Nenad

You can fix it like this:

const data = await page.$eval(selector, node => (node as HTMLElement).innerText);

or:

const data = await page.$eval(selector, node => (<HTMLElement>node).innerText);

UPDATE:

So, after some exchange on Github, it's clear why the syntax from this question does not work. It actually defines anonymous generic function.

<HTMLElement>(node: HTMLElement) => node.innerText

Clearer example would be following:

function myFunction<T>(node: T) {
    node.innerText; // Property 'innerText' does not exist on 'T'
}

const data = await page.$eval(selector, myFunction);

Unfortunate naming of T as HTMLElement creates confusion.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

'Property does not exist on type 'never'

分類Dev

Property 'xxx' does not exist on type '{}'

分類Dev

Property 'values' does not exist on type 'ObjectConstructor'

分類Dev

Property 'values' does not exist on type 'ObjectConstructor'

分類Dev

property then does not exist on type void , A typescript error

分類Dev

TSLint: Property 'params' does not exist on type 'NavigationState'

分類Dev

Property 'subscribe' does not exist on type 'Subscription

分類Dev

Property 'entries' does not exist on type ObjectConstructor

分類Dev

Property 'VAR_PLURAL' does not exist on type

分類Dev

Typescript: Property 'DB' does not exist on type 'Global'

分類Dev

Property 'detailed' does not exist on type 'Console'

分類Dev

Typescript property does not exist on union type

分類Dev

Property 'store' does not exist on type 'Readonly<AppInitialProps

分類Dev

Generic property 'enabled' does not exist on type 'Node'?

分類Dev

How to define a property to avoid: Property 'X' does not exist on type 'Y'

分類Dev

How to prevent "Property '...' does not exist on type 'Global'" with jsdom and typescript?

分類Dev

Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

分類Dev

how to fix property does not exist on type 'Object' in ionic 3?

分類Dev

useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'

分類Dev

Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable'

分類Dev

Angular 5 : Property 'then' does not exist on type 'Observable<any>'

分類Dev

Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

分類Dev

Typescript - property scan does not exist on type Subject...?

分類Dev

Property 'filter' does not exist on type 'Object'. When trying to filter response

分類Dev

ES6: Property 'selected' does not exist on type 'Object'

分類Dev

Property 'controls' does not exist on type 'AbstractControl'. in angular 8

分類Dev

Property 'background' does not exist on type '{}' - React Router modal

分類Dev

Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'

分類Dev

Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'

Related 関連記事

  1. 1

    'Property does not exist on type 'never'

  2. 2

    Property 'xxx' does not exist on type '{}'

  3. 3

    Property 'values' does not exist on type 'ObjectConstructor'

  4. 4

    Property 'values' does not exist on type 'ObjectConstructor'

  5. 5

    property then does not exist on type void , A typescript error

  6. 6

    TSLint: Property 'params' does not exist on type 'NavigationState'

  7. 7

    Property 'subscribe' does not exist on type 'Subscription

  8. 8

    Property 'entries' does not exist on type ObjectConstructor

  9. 9

    Property 'VAR_PLURAL' does not exist on type

  10. 10

    Typescript: Property 'DB' does not exist on type 'Global'

  11. 11

    Property 'detailed' does not exist on type 'Console'

  12. 12

    Typescript property does not exist on union type

  13. 13

    Property 'store' does not exist on type 'Readonly<AppInitialProps

  14. 14

    Generic property 'enabled' does not exist on type 'Node'?

  15. 15

    How to define a property to avoid: Property 'X' does not exist on type 'Y'

  16. 16

    How to prevent "Property '...' does not exist on type 'Global'" with jsdom and typescript?

  17. 17

    Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

  18. 18

    how to fix property does not exist on type 'Object' in ionic 3?

  19. 19

    useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'

  20. 20

    Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable'

  21. 21

    Angular 5 : Property 'then' does not exist on type 'Observable<any>'

  22. 22

    Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

  23. 23

    Typescript - property scan does not exist on type Subject...?

  24. 24

    Property 'filter' does not exist on type 'Object'. When trying to filter response

  25. 25

    ES6: Property 'selected' does not exist on type 'Object'

  26. 26

    Property 'controls' does not exist on type 'AbstractControl'. in angular 8

  27. 27

    Property 'background' does not exist on type '{}' - React Router modal

  28. 28

    Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'

  29. 29

    Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'

ホットタグ

アーカイブ