@@ -97,9 +97,10 @@ function canSuggest(
97
97
currentMethod : string ,
98
98
requestedMethod : string | undefined ,
99
99
data : string | null ,
100
- ) {
100
+ ) : data is string {
101
101
return (
102
- data &&
102
+ typeof data === 'string' &&
103
+ data . length > 0 &&
103
104
( ! requestedMethod ||
104
105
requestedMethod . toLowerCase ( ) === currentMethod . toLowerCase ( ) )
105
106
)
@@ -137,14 +138,9 @@ export function getSuggestedQuery(
137
138
138
139
const placeholderText = element . getAttribute ( 'placeholder' )
139
140
if ( canSuggest ( 'PlaceholderText' , method , placeholderText ) ) {
140
- return makeSuggestion (
141
- 'PlaceholderText' ,
142
- element ,
143
- placeholderText as string ,
144
- {
145
- variant,
146
- } ,
147
- )
141
+ return makeSuggestion ( 'PlaceholderText' , element , placeholderText , {
142
+ variant,
143
+ } )
148
144
}
149
145
150
146
const textContent = normalize ( getNodeText ( element ) )
@@ -160,17 +156,17 @@ export function getSuggestedQuery(
160
156
161
157
const alt = element . getAttribute ( 'alt' )
162
158
if ( canSuggest ( 'AltText' , method , alt ) ) {
163
- return makeSuggestion ( 'AltText' , element , alt as string , { variant} )
159
+ return makeSuggestion ( 'AltText' , element , alt , { variant} )
164
160
}
165
161
166
162
const title = element . getAttribute ( 'title' )
167
163
if ( canSuggest ( 'Title' , method , title ) ) {
168
- return makeSuggestion ( 'Title' , element , title as string , { variant} )
164
+ return makeSuggestion ( 'Title' , element , title , { variant} )
169
165
}
170
166
171
167
const testId = element . getAttribute ( getConfig ( ) . testIdAttribute )
172
168
if ( canSuggest ( 'TestId' , method , testId ) ) {
173
- return makeSuggestion ( 'TestId' , element , testId as string , { variant} )
169
+ return makeSuggestion ( 'TestId' , element , testId , { variant} )
174
170
}
175
171
176
172
return undefined
0 commit comments