Skip to content

Commit 8d5470d

Browse files
committed
Use multiline comments for better IDE support
1 parent d5ead3d commit 8d5470d

File tree

10 files changed

+29
-10
lines changed

10 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning].
99

1010
## Added
1111

12+
- Add support for comments in generated TypeScript interfaces ([@envek])
1213
- Add TypeScript verbatim module syntax support through `verbatim_module_syntax` config option ([@patvice])
1314
- Add `typelizer:generate:refresh` command to clean output directory and regenerate all interfaces ([@patvice])
1415
- Allow disabling Typelizer in Rails development with `DISABLE_TYPELIZER` environment variable to `true` ([@okuramasafumi])
@@ -69,6 +70,7 @@ and this project adheres to [Semantic Versioning].
6970
- Initial release ([@skryukov])
7071

7172
[@davidrunger]: https://github.com/davidrunger
73+
[@envek]: https://github.com/envek
7274
[@okuramasafumi]: https://github.com/okuramasafumi
7375
[@patvice]: https://github.com/patvice
7476
[@skryukov]: https://github.com/skryukov

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Typelizer is a Ruby gem that automatically generates TypeScript interfaces from
1414
- [TypeScript Integration](#typescript-integration)
1515
- [Manual Generation](#manual-generation)
1616
- [Automatic Generation in Development](#automatic-generation-in-development)
17+
- [Disabling Typelizer](#disabling-typelizer)
1718
- [Configuration](#configuration)
1819
- [Global Configuration](#global-configuration)
1920
- [Config Options](#config-options)
@@ -79,6 +80,11 @@ class PostResource < ApplicationResource
7980
attribute :author_name do |post|
8081
post.author.name
8182
end
83+
84+
typelize :string, nullable: true, comment: "Author's avatar URL"
85+
attribute :avatar do
86+
"https://example.com/avatar.png" if active?
87+
end
8288
end
8389
```
8490

@@ -259,6 +265,10 @@ Typelizer.configure do |config|
259265
# Support TypeScript's Verbatim module syntax option (default: false)
260266
# Will change imports and exports of types from default to support this syntax option
261267
config.verbatim_module_syntax = false
268+
269+
# Support comments in generated TypeScript interfaces (default: false)
270+
# Will add comments to the generated interfaces
271+
config.comments = false
262272
end
263273
```
264274

lib/typelizer/templates/interface.ts.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type <%= interface.name %> = {
1818
<%- else -%>
1919
type <%= interface.name %> = {
2020
<%- interface.properties.each do |property| -%>
21-
<%= indent("// #{property.comment.tr("\n", '\n')}\n") if interface.config.comments && property.comment -%>
21+
<%= indent("/** #{property.comment.split("\n").map(&:strip).join("\n * ")} */\n") if interface.config.comments && property.comment -%>
2222
<%= indent(property) %>;
2323
<%- end -%>
2424
}

spec/__snapshots__/AlbaUserAuthor.ts.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// Typelizer digest 5853f063c6c19b98aeeee99e9c29980a
1+
// Typelizer digest 6a70418b072c53d25848cea380599d44
22
//
33
// DO NOT MODIFY: This file was automatically generated by Typelizer.
44
import type {AlbaPost} from '@/types'
55

66
type AlbaUserAuthor = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
posts?: Array<AlbaPost>;
1111
avatar: unknown;
12+
/** Typed avatar URL
13+
* Active user only */
1214
typed_avatar: string | null;
1315
}
1416

spec/__snapshots__/AlbaUserEmptyNested.ts.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// Typelizer digest 3bf7801f630edffea7eefdcb86e3fb74
1+
// Typelizer digest 149809de5e88dc7e93c61dd1c8df854d
22
//
33
// DO NOT MODIFY: This file was automatically generated by Typelizer.
44
import type {AlbaPost} from '@/types'
55

66
type AlbaUserEmptyNested = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
posts?: Array<AlbaPost>;
1111
avatar: unknown;
12+
/** Typed avatar URL
13+
* Active user only */
1214
typed_avatar: string | null;
1315
}
1416

spec/__snapshots__/AmsUserAuthor.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {AmsPost} from '@/types'
55

66
type AmsUserAuthor = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
avatar: unknown;
1111
typed_avatar: string | null;

spec/__snapshots__/AmsUserEmptyNested.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {AmsPost} from '@/types'
55

66
type AmsUserEmptyNested = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
avatar: unknown;
1111
typed_avatar: string | null;

spec/__snapshots__/OjSerializersUserAuthor.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {OjSerializersPost} from '@/types'
55

66
type OjSerializersUserAuthor = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
posts?: Array<OjSerializersPost>;
1111
avatar: unknown;

spec/__snapshots__/OjSerializersUserEmptyNested.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {OjSerializersPost} from '@/types'
55

66
type OjSerializersUserEmptyNested = {
77
id: number;
8-
// Author login handle
8+
/** Author login handle */
99
username: string | null;
1010
posts?: Array<OjSerializersPost>;
1111
avatar: unknown;

spec/app/app/serializers/alba/user/author_serializer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class AuthorSerializer < BaseSerializer
1515
# typelize typed_avatar: [:string, nullable: true]
1616
# typelize ["string", "null"]
1717
# typelize "string | null"
18-
typelize :string, nullable: true
18+
typelize :string, nullable: true, comment: <<~TXT
19+
Typed avatar URL
20+
Active user only
21+
TXT
1922
attribute :typed_avatar do
2023
"https://example.com/avatar.png" if active?
2124
end

0 commit comments

Comments
 (0)