1- import * as React from 'react' ;
21import { ErrorWithStack } from '../helpers/errors' ;
32import { createQueryByError } from '../helpers/errors' ;
43import { findAll } from '../helpers/find-all' ;
54import { HostElement } from '../renderer/host-element' ;
65
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 ) {
118 const results = findAllByType ( instance , type ) ;
129 if ( results . length === 0 ) {
1310 throw new ErrorWithStack ( `No instances found with type:\n${ type } ` , getByTypeFn ) ;
@@ -18,21 +15,17 @@ const UNSAFE_getByType = (
1815 return results [ 0 ] ;
1916 } ;
2017
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 ) {
2520 const results = findAllByType ( instance , type ) ;
2621 if ( results . length === 0 ) {
2722 throw new ErrorWithStack ( `No instances found with type:\n${ type } ` , getAllByTypeFn ) ;
2823 }
2924 return results ;
3025 } ;
3126
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 ) {
3629 try {
3730 return UNSAFE_getByType ( instance ) ( type ) ;
3831 } catch ( error ) {
@@ -41,8 +34,8 @@ const UNSAFE_queryByType = (
4134 } ;
4235
4336const 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 ) => {
4639 try {
4740 return UNSAFE_getAllByType ( instance ) ( type ) ;
4841 } catch {
@@ -52,10 +45,10 @@ const UNSAFE_queryAllByType =
5245
5346// Unsafe aliases
5447export 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 > ;
5952} ;
6053
6154// TODO: migrate to makeQueries pattern
@@ -66,7 +59,6 @@ export const bindUnsafeByTypeQueries = (instance: HostElement): UnsafeByTypeQuer
6659 UNSAFE_queryAllByType : UNSAFE_queryAllByType ( instance ) ,
6760} ) ;
6861
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 ) {
7163 return findAll ( instance , ( element ) => element . type === type ) ;
7264}
0 commit comments