Skip to content

Commit 80926bd

Browse files
committed
feat: array with bracket notation config
1 parent cfa24b8 commit 80926bd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/anchor/config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Config
77
:infer_nullable_relationships_as_optional,
88
:empty_relationship_type,
99
:use_type_as_schema_name,
10-
:maybe_as_union
10+
:maybe_as_union,
11+
:array_bracket_notation
1112

1213
def initialize
1314
@ar_column_to_type = nil
@@ -18,6 +19,7 @@ def initialize
1819
@empty_relationship_type = nil
1920
@use_type_as_schema_name = nil
2021
@maybe_as_union = nil
22+
@array_bracket_notation = nil
2123
end
2224
end
2325
end

lib/anchor/type_script/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def type_string(type, depth = 1)
1212
when Anchor::Types::Record, Anchor::Types::Record.singleton_class then "Record<string, #{type_string(type.try(:value_type) || Anchor::Types::Unknown)}>"
1313
when Anchor::Types::Union then type.types.map { |type| type_string(type, depth) }.join(" | ")
1414
when Anchor::Types::Maybe then Anchor.config.maybe_as_union ? type_string(Anchor::Types::Union.new([type.type, Anchor::Types::Null]), depth) : "Maybe<#{type_string(type.type, depth)}>"
15-
when Anchor::Types::Array then "Array<#{type_string(type.type, depth)}>"
15+
when Anchor::Types::Array then Anchor.config.array_bracket_notation ? "#{type_string(type.type, depth)}[]" : "Array<#{type_string(type.type, depth)}>"
1616
when Anchor::Types::Literal then serialize_literal(type.value)
1717
when Anchor::Types::Reference then type.name
1818
when Anchor::Types::Object, Anchor::Types::Object.singleton_class then serialize_object(type, depth)

0 commit comments

Comments
 (0)