Skip to content

Commit

Permalink
feat: introduced ts types, added test data
Browse files Browse the repository at this point in the history
  • Loading branch information
ariansobczak-rst committed Jan 18, 2022
1 parent 7011942 commit 0bfe834
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 20 additions & 0 deletions fixtures/typescript/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Example of union type definition
*/
type SomeCombinedType = string | number | 'Specific string' | SomeOtherType;


/**
* Example of simple type definition
*/
type SomeOtherType = boolean;

/**
* Example of generic type definition with T as parameter
*/
type SomeGenericType<T> = T | SomeOtherGenericType<T> | { property: T, other: string }

/**
* Example of generic type definition with T as parameter
*/
type SomeOtherGenericType<T> = { children: T[] }
9 changes: 7 additions & 2 deletions typescript/type-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
if (jsDocNode) {
let comment = src.substring(jsDocNode.pos, jsDocNode.end)
const name = getName(statement, src)

if (ts.isTypeAliasDeclaration(statement)) {
if (ts.isFunctionTypeNode(statement.type)) {
comment = appendComment(comment, `@typedef {function} ${name}`)
return convertParams(comment, statement, src)
}
}
if (ts.isTypeLiteralNode(statement.type)) {
comment = appendComment(comment, `@typedef {object} ${name}`)
return convertMembers(comment, statement.type, src)
Expand All @@ -161,6 +161,11 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
comment = appendComment(comment, `@typedef {object} ${name}`)
return convertMembers(comment, statement.type, src)
}
if (ts.isUnionTypeNode(statement.type) || ts.isSimpleInlineableExpression(statement.type)) {
let typeName = getTypeName(statement.type, src)
comment = appendComment(comment, `@typedef {${typeName}} ${name}`)
return convertMembers(comment, statement.type, src)
}
}
if (ts.isInterfaceDeclaration(statement)) {
comment = appendComment(comment, `@interface ${name}`)
Expand Down

0 comments on commit 0bfe834

Please sign in to comment.