Skip to content

Commit 0bfe834

Browse files
feat: introduced ts types, added test data
1 parent 7011942 commit 0bfe834

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

fixtures/typescript/type.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Example of union type definition
3+
*/
4+
type SomeCombinedType = string | number | 'Specific string' | SomeOtherType;
5+
6+
7+
/**
8+
* Example of simple type definition
9+
*/
10+
type SomeOtherType = boolean;
11+
12+
/**
13+
* Example of generic type definition with T as parameter
14+
*/
15+
type SomeGenericType<T> = T | SomeOtherGenericType<T> | { property: T, other: string }
16+
17+
/**
18+
* Example of generic type definition with T as parameter
19+
*/
20+
type SomeOtherGenericType<T> = { children: T[] }

typescript/type-converter.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
147147
if (jsDocNode) {
148148
let comment = src.substring(jsDocNode.pos, jsDocNode.end)
149149
const name = getName(statement, src)
150-
150+
151151
if (ts.isTypeAliasDeclaration(statement)) {
152152
if (ts.isFunctionTypeNode(statement.type)) {
153153
comment = appendComment(comment, `@typedef {function} ${name}`)
154154
return convertParams(comment, statement, src)
155-
}
155+
}
156156
if (ts.isTypeLiteralNode(statement.type)) {
157157
comment = appendComment(comment, `@typedef {object} ${name}`)
158158
return convertMembers(comment, statement.type, src)
@@ -161,6 +161,11 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
161161
comment = appendComment(comment, `@typedef {object} ${name}`)
162162
return convertMembers(comment, statement.type, src)
163163
}
164+
if (ts.isUnionTypeNode(statement.type) || ts.isSimpleInlineableExpression(statement.type)) {
165+
let typeName = getTypeName(statement.type, src)
166+
comment = appendComment(comment, `@typedef {${typeName}} ${name}`)
167+
return convertMembers(comment, statement.type, src)
168+
}
164169
}
165170
if (ts.isInterfaceDeclaration(statement)) {
166171
comment = appendComment(comment, `@interface ${name}`)

0 commit comments

Comments
 (0)