1
- import * as React from 'react' ;
2
1
import { ErrorWithStack } from '../helpers/errors' ;
3
2
import { createQueryByError } from '../helpers/errors' ;
4
3
import { findAll } from '../helpers/find-all' ;
5
4
import { HostElement } from '../renderer/host-element' ;
6
5
7
- const UNSAFE_getByType = (
8
- instance : HostElement ,
9
- ) : ( ( type : React . ComponentType < any > ) => HostElement ) =>
10
- function getByTypeFn ( type : React . ComponentType < any > ) {
6
+ const UNSAFE_getByType = ( instance : HostElement ) : ( ( type : string ) => HostElement ) =>
7
+ function getByTypeFn ( type : string ) {
11
8
const results = findAllByType ( instance , type ) ;
12
9
if ( results . length === 0 ) {
13
10
throw new ErrorWithStack ( `No instances found with type:\n${ type } ` , getByTypeFn ) ;
@@ -18,21 +15,17 @@ const UNSAFE_getByType = (
18
15
return results [ 0 ] ;
19
16
} ;
20
17
21
- const UNSAFE_getAllByType = (
22
- instance : HostElement ,
23
- ) : ( ( type : React . ComponentType < any > ) => Array < HostElement > ) =>
24
- function getAllByTypeFn ( type : React . ComponentType < any > ) {
18
+ const UNSAFE_getAllByType = ( instance : HostElement ) : ( ( type : string ) => Array < HostElement > ) =>
19
+ function getAllByTypeFn ( type : string ) {
25
20
const results = findAllByType ( instance , type ) ;
26
21
if ( results . length === 0 ) {
27
22
throw new ErrorWithStack ( `No instances found with type:\n${ type } ` , getAllByTypeFn ) ;
28
23
}
29
24
return results ;
30
25
} ;
31
26
32
- const UNSAFE_queryByType = (
33
- instance : HostElement ,
34
- ) : ( ( type : React . ComponentType < any > ) => HostElement | null ) =>
35
- function queryByTypeFn ( type : React . ComponentType < any > ) {
27
+ const UNSAFE_queryByType = ( instance : HostElement ) : ( ( type : string ) => HostElement | null ) =>
28
+ function queryByTypeFn ( type : string ) {
36
29
try {
37
30
return UNSAFE_getByType ( instance ) ( type ) ;
38
31
} catch ( error ) {
@@ -41,8 +34,8 @@ const UNSAFE_queryByType = (
41
34
} ;
42
35
43
36
const UNSAFE_queryAllByType =
44
- ( instance : HostElement ) : ( ( type : React . ComponentType < any > ) => Array < HostElement > ) =>
45
- ( type : React . ComponentType < any > ) => {
37
+ ( instance : HostElement ) : ( ( type : string ) => Array < HostElement > ) =>
38
+ ( type : string ) => {
46
39
try {
47
40
return UNSAFE_getAllByType ( instance ) ( type ) ;
48
41
} catch {
@@ -52,10 +45,10 @@ const UNSAFE_queryAllByType =
52
45
53
46
// Unsafe aliases
54
47
export type UnsafeByTypeQueries = {
55
- UNSAFE_getByType : < P > ( type : React . ComponentType < P > ) => HostElement ;
56
- UNSAFE_getAllByType : < P > ( type : React . ComponentType < P > ) => Array < HostElement > ;
57
- UNSAFE_queryByType : < P > ( type : React . ComponentType < P > ) => HostElement | null ;
58
- UNSAFE_queryAllByType : < P > ( type : React . ComponentType < P > ) => Array < HostElement > ;
48
+ UNSAFE_getByType : ( type : string ) => HostElement ;
49
+ UNSAFE_getAllByType : ( type : string ) => Array < HostElement > ;
50
+ UNSAFE_queryByType : ( type : string ) => HostElement | null ;
51
+ UNSAFE_queryAllByType : ( type : string ) => Array < HostElement > ;
59
52
} ;
60
53
61
54
// TODO: migrate to makeQueries pattern
@@ -66,7 +59,6 @@ export const bindUnsafeByTypeQueries = (instance: HostElement): UnsafeByTypeQuer
66
59
UNSAFE_queryAllByType : UNSAFE_queryAllByType ( instance ) ,
67
60
} ) ;
68
61
69
- function findAllByType ( instance : HostElement , type : React . ComponentType < any > ) {
70
- // @ts -expect-error: React.ComponentType<any> is not compatible with string
62
+ function findAllByType ( instance : HostElement , type : string ) {
71
63
return findAll ( instance , ( element ) => element . type === type ) ;
72
64
}
0 commit comments