@@ -87,7 +87,7 @@ function getSelectedText() {
8787 const element = elements [ i ] . getElement ( ) ;
8888 // Only translate elements that can be edited as text; skip images and
8989 // other non-text elements.
90- if ( ( /** @type { any } */ ( element ) ) . editAsText ) {
90+ if ( element . getType ( ) === DocumentApp . ElementType . TEXT ) {
9191 const elementText = element . asText ( ) . getText ( ) ;
9292 // This check is necessary to exclude images, which return a blank
9393 // text element.
@@ -190,19 +190,21 @@ function insertText(newText) {
190190 }
191191 } else {
192192 const element = elements [ i ] . getElement ( ) ;
193- if ( ! replaced && ( /** @type {any } */ ( element ) ) . editAsText ) {
194- // Only translate elements that can be edited as text, removing other
195- // elements.
196- ( /** @type {any } */ ( element ) ) . clear ( ) ;
197- element . asText ( ) . setText ( newText ) ;
193+ // Only translate elements that can be edited as text; skip images and
194+ // other non-text elements.
195+ const type = element . getType ( ) ;
196+ if ( ! replaced && type === DocumentApp . ElementType . TEXT ) {
197+ const textElement = element . asText ( ) ;
198+ textElement . clear ( ) ;
199+ textElement . setText ( newText ) ;
198200 replaced = true ;
199201 } else {
200202 // We cannot remove the last paragraph of a doc. If this is the case,
201203 // just clear the element.
202204 if ( element . getNextSibling ( ) ) {
203205 element . removeFromParent ( ) ;
204- } else {
205- ( /** @type { any } */ ( element ) ) . clear ( ) ;
206+ } else if ( type === DocumentApp . ElementType . TEXT ) {
207+ element . asText ( ) . clear ( ) ;
206208 }
207209 }
208210 }
0 commit comments