From 0f9a25b2f33bd7558db2b7eb4dee41eea2d5707d Mon Sep 17 00:00:00 2001 From: Arian Sobczak Date: Thu, 20 Jan 2022 11:53:19 +0100 Subject: [PATCH] fix: fixed handle empty types while class functions converting --- typescript/type-converter.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/typescript/type-converter.js b/typescript/type-converter.js index 4ac460b..19379f7 100644 --- a/typescript/type-converter.js +++ b/typescript/type-converter.js @@ -12,6 +12,7 @@ const appendComment = (commentBlock, toAppend) => { * @returns {string} node type */ const getTypeName = (type, src) => { + if(!type) { return ''} if (type.typeName && type.typeName.escapedText) { const typeName = type.typeName.escapedText if(type.typeArguments && type.typeArguments.length) { @@ -213,10 +214,14 @@ module.exports = function typeConverter(src, filename = 'test.ts') { memberComment = appendComment(memberComment, `@type {${type}}`) } if (member.type && ts.isFunctionLike(member)) { - memberComment = appendComment(memberComment, '@method') - memberComment = convertParams(memberComment, member, src) - memberComment = convertMembers(memberComment, member.type, src) - memberComment = appendComment(memberComment, `@return {${getTypeName(member.type, src)}}`) + try { + memberComment = appendComment(memberComment, '@method') + memberComment = convertParams(memberComment, member, src) + memberComment = convertMembers(memberComment, member.type, src) + memberComment = appendComment(memberComment, `@return {${getTypeName(member.type, src)}}`) + } catch (error) { + console.log(error); + } } if (modifiers.find((m => m === 'static'))) { memberComment += '\n' + `${className}.${getName(member, src)}`