Skip to content

Commit 637a208

Browse files
Merge pull request #182 from SoftwareBrothers/handle-ts-types-definitions
feat: handle TS types definitions
2 parents 9929ce0 + 8f19ed7 commit 637a208

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

fixtures/interface.ts renamed to fixtures/typescript/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export enum PropertyPlace {
88
/**
99
* JSON representation of a Property.
1010
*/
11-
type PropertyJSON = {
11+
interface PropertyJSON {
1212
/**
1313
* If given property should be treated as a title
1414
*/

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[] }

tmpl/type.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
var data = obj;
33
var self = this;
44
data.forEach(function(name, i) { ?>
5-
<span class="param-type"><?js= self.linkto(name, self.htmlsafe(name)) ?></span>
5+
<code class="param-type"><?js= self.linkto(name, self.htmlsafe(name)) ?></code>
66
<?js if (i < data.length-1) { ?>|<?js } ?>
77
<?js }); ?>

typescript/type-converter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
163163
comment = appendComment(comment, `@typedef {object} ${name}`)
164164
return convertMembers(comment, statement.type, src)
165165
}
166+
if (ts.isUnionTypeNode(statement.type) || ts.isSimpleInlineableExpression(statement.type)) {
167+
let typeName = getTypeName(statement.type, src)
168+
comment = appendComment(comment, `@typedef {${typeName}} ${name}`)
169+
return convertMembers(comment, statement.type, src)
170+
}
166171
}
167172
if (ts.isInterfaceDeclaration(statement)) {
168173
comment = appendComment(comment, `@interface ${name}`)

typescript/type-converter.spec.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
const fs = require('fs')
2-
const path = require('path')
31
const { expect } = require('chai')
42
const typeConverter = require('./type-converter')
53

6-
const src = fs.readFileSync(path.join(__dirname, '../fixtures/typescript/entity.ts'), 'utf-8')
7-
84
const interface1 = require('../fixtures/typescript/interface1')
95
const interface2 = require('../fixtures/typescript/interface2')
106
const interface3 = require('../fixtures/typescript/interface3')
@@ -98,8 +94,5 @@ describe('.typeConverter', function () {
9894
})
9995
})
10096

101-
102-
// it.only('parses test', function() {
103-
// console.log(typeConverter(src, '../fixtures/interface.ts'))
104-
// })
97+
// TODO: Provide tests for typescript
10598
})

0 commit comments

Comments
 (0)