Skip to content

Commit

Permalink
support verbatim module syntax option in typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
patvice committed Oct 31, 2024
1 parent c1a24e9 commit d617688
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ Typelizer.configure do |config|
# List of type names that should be considered global in TypeScript
# (i.e. not prefixed with the import path)
config.types_global << %w[Array Date Record File FileList]

# Support TypeScript's Verbatim module syntax option (default: false)
# Will change imports and exports of types from default to support this syntax option
config.verbatim_module_syntax = false
end
```

Expand Down
5 changes: 3 additions & 2 deletions lib/typelizer/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Config < Struct.new(
:output_dir,
:types_import_path,
:types_global,
:verbatim_module_syntax,
keyword_init: true
) do
class << self
Expand Down Expand Up @@ -51,7 +52,8 @@ def instance
types_import_path: "@/types",
types_global: %w[Array Date Record File FileList],

properties_transformer: nil
properties_transformer: nil,
verbatim_module_syntax: false
)
end

Expand All @@ -70,7 +72,6 @@ def respond_to_missing?(name, include_private = false)

def method_missing(method, *args, &block)
return Typelizer.send(method, *args, &block) if Typelizer.respond_to?(method)

instance.send(method, *args, &block)
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/typelizer/templates/index.ts.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<%- interfaces.each do |interface| -%>
<%- if interface.config.verbatim_module_syntax -%>
export type { <%= interface.name %> } from './<%= interface.filename %>'
<%- else -%>
export type { default as <%= interface.name %> } from './<%= interface.filename %>'
<%- end -%>
<%- end -%>
4 changes: 4 additions & 0 deletions lib/typelizer/templates/interface.ts.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ type <%= interface.name %> = {
}
<%- end -%>

<%-if interface.config.verbatim_module_syntax -%>
export type { <%= interface.name %> };
<%- else -%>
export default <%= interface.name %>;
<%- end -%>

0 comments on commit d617688

Please sign in to comment.