diff --git a/README.md b/README.md index d3a15c2..6481612 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/lib/typelizer/config.rb b/lib/typelizer/config.rb index e7d0fff..2e028f5 100644 --- a/lib/typelizer/config.rb +++ b/lib/typelizer/config.rb @@ -24,6 +24,7 @@ class Config < Struct.new( :output_dir, :types_import_path, :types_global, + :verbatim_module_syntax, keyword_init: true ) do class << self @@ -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 @@ -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 diff --git a/lib/typelizer/templates/index.ts.erb b/lib/typelizer/templates/index.ts.erb index 6e368c2..5f58654 100644 --- a/lib/typelizer/templates/index.ts.erb +++ b/lib/typelizer/templates/index.ts.erb @@ -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 -%> diff --git a/lib/typelizer/templates/interface.ts.erb b/lib/typelizer/templates/interface.ts.erb index 1daee04..9e766a1 100644 --- a/lib/typelizer/templates/interface.ts.erb +++ b/lib/typelizer/templates/interface.ts.erb @@ -23,4 +23,8 @@ type <%= interface.name %> = { } <%- end -%> +<%-if interface.config.verbatim_module_syntax -%> +export type { <%= interface.name %> }; +<%- else -%> export default <%= interface.name %>; +<%- end -%>