mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: make $ and $$ selectors generic (#6883)
* fix: make `$` and `$$` selectors generic
This means, much like TS's in built `querySelector` type, you can now do:
```ts
const listItems = page.$$<HTMLLIElement>('ul li');
```
And/or:
```ts
const h2 = page.$<HTMLHeadingElement>('h2');
```
And the return value will be of type `ElementHandle<T>|null`, where `T`
is the type you provided. By default `T` is an `Element`, so you don't
have to provide this if you don't care as a consumer about the exact
type you get back.
* chore: fix test assertions
This commit is contained in:
@@ -34,7 +34,7 @@ const EXPECTED_ERRORS = new Map<string, string[]>([
|
||||
"bad.js(5,35): error TS2551: Property 'launh' does not exist on type",
|
||||
"bad.js(7,29): error TS2551: Property 'devics' does not exist on type",
|
||||
'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.',
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<Element> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<HTMLElement> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -43,7 +43,7 @@ const EXPECTED_ERRORS = new Map<string, string[]>([
|
||||
"bad.js(5,35): error TS2551: Property 'launh' does not exist on type",
|
||||
"bad.js(7,29): error TS2551: Property 'devics' does not exist on type",
|
||||
'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.',
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<Element> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<HTMLElement> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -52,7 +52,7 @@ const EXPECTED_ERRORS = new Map<string, string[]>([
|
||||
"bad.js(5,35): error TS2551: Property 'launh' does not exist on type",
|
||||
"bad.js(7,29): error TS2551: Property 'devics' does not exist on type",
|
||||
'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.',
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<Element> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<HTMLElement> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -61,7 +61,7 @@ const EXPECTED_ERRORS = new Map<string, string[]>([
|
||||
"bad.js(5,35): error TS2551: Property 'launh' does not exist on type",
|
||||
"bad.js(7,29): error TS2551: Property 'devics' does not exist on type",
|
||||
'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.',
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<Element> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
"bad.js(15,9): error TS2322: Type 'ElementHandle<HTMLElement> | null' is not assignable to type 'ElementHandle<HTMLElement>'",
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user