@@ -420,13 +420,13 @@ async function convert_to_ts(js_code: string, indent = '', offset = '') {
420420
421421 for ( const tag of tags ) {
422422 if ( ts . isJSDocTypeTag ( tag ) ) {
423- type = get_type_info ( tag . typeExpression ) ;
423+ type = get_type_info ( get_jsdoc_type_expression_text ( tag . getText ( ) ) ) ;
424424 } else if ( ts . isJSDocParameterTag ( tag ) ) {
425- params . push ( get_type_info ( tag . typeExpression ! ) ) ;
425+ params . push ( get_type_info ( tag . typeExpression ?. getText ( ) ! ) ) ;
426426 } else if ( ts . isJSDocReturnTag ( tag ) ) {
427- returns = get_type_info ( tag . typeExpression ! ) ;
427+ returns = get_type_info ( tag . typeExpression ?. getText ( ) ! ) ;
428428 } else if ( ts . isJSDocSatisfiesTag ( tag ) ) {
429- satisfies = get_type_info ( tag . typeExpression ! ) ;
429+ satisfies = get_type_info ( tag . typeExpression ?. getText ( ) ! ) ;
430430 } else {
431431 throw new Error ( 'Unhandled tag' ) ;
432432 }
@@ -546,10 +546,9 @@ async function convert_to_ts(js_code: string, indent = '', offset = '') {
546546
547547 return transformed === js_code ? undefined : transformed ;
548548
549- function get_type_info ( expression : ts . JSDocTypeExpression ) {
550- const type = expression
551- ?. getText ( ) !
552- . slice ( 1 , - 1 ) // remove surrounding `{` and `}`
549+ function get_type_info ( expressionText : string ) {
550+ const type = expressionText
551+ . replace ( / ^ \{ | \} $ / g, '' ) // remove surrounding `{` and `}`
553552 . replace ( / \* ? / gm, '' )
554553 . replace ( / i m p o r t \( ' ( .+ ?) ' \) \. ( \w + ) (?: ( < .+ > ) ) ? / gms, ( _ , source , name , args = '' ) => {
555554 const existing = imports . get ( source ) ;
@@ -564,6 +563,10 @@ async function convert_to_ts(js_code: string, indent = '', offset = '') {
564563
565564 return type ;
566565 }
566+
567+ function get_jsdoc_type_expression_text ( jsdocText : string ) : string {
568+ return jsdocText . replace ( / ^ @ t y p e \s * / , '' ) . trim ( ) ;
569+ }
567570}
568571
569572function find_nearest_node_modules ( file : string ) : string | null {
0 commit comments