sorbet-coerce 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configuration.rb +2 -2
- data/lib/private/converter.rb +13 -6
- data/lib/sorbet-coerce.rb +3 -3
- data/rbi/sorbet-coerce.rbi +10 -10
- data/spec/coerce_spec.rb +67 -44
- data/spec/nested_spec.rb +9 -9
- data/spec/soft_error_spec.rb +10 -10
- data/spec/sorbet_test_cases.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f267197b77c7b2c9ed7558ad7f94818fc54f9af5fc56c99c9d824af47e40bf78
|
4
|
+
data.tar.gz: 04da4e2a3ebdde38cf4d2e6d60200c365d371250f9d33f588f67adc5b766c6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee1d39f9e9b12ebdb2d3f1f9c4066ef2f7707329dfe10ab3330fc33b9e943ae9560028ec467203efad12bad567eb5b226ae4669be0b378bf1897a3ca84fbe37
|
7
|
+
data.tar.gz: a989b4a83745234e88e5c1ba5f26bda2d57be9ec0f61d26d4ece75f5db68bc88130fad68ec9fd43c6a4a44ae263231b65c8a0235bd34188b9c875f377ad9ddee
|
data/lib/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# typed: true
|
2
2
|
require 'sorbet-runtime'
|
3
3
|
|
4
|
-
module
|
4
|
+
module TypeCoerce
|
5
5
|
module Configuration
|
6
6
|
class << self
|
7
7
|
extend T::Sig
|
@@ -12,4 +12,4 @@ module T::Coerce
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
TypeCoerce::Configuration.raise_coercion_error = true
|
data/lib/private/converter.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# typed: strict
|
2
2
|
require 'safe_type'
|
3
|
+
require 'set'
|
3
4
|
require 'sorbet-runtime'
|
4
5
|
require 'polyfill'
|
5
6
|
|
6
7
|
using Polyfill(Hash: %w[#slice])
|
7
8
|
|
8
|
-
module
|
9
|
+
module TypeCoerce; end
|
10
|
+
|
11
|
+
module TypeCoerce::Private
|
9
12
|
class Converter
|
10
13
|
extend T::Sig
|
11
14
|
|
@@ -22,8 +25,12 @@ module T::Private
|
|
22
25
|
protected
|
23
26
|
sig { params(value: T.untyped, type: T.untyped, raise_coercion_error: T::Boolean).returns(T.untyped) }
|
24
27
|
def _convert(value, type, raise_coercion_error)
|
25
|
-
if type.is_a?(T::Types::
|
28
|
+
if type.is_a?(T::Types::Untyped)
|
29
|
+
value
|
30
|
+
elsif type.is_a?(T::Types::TypedArray)
|
26
31
|
_convert_to_a(value, type.type, raise_coercion_error)
|
32
|
+
elsif type.is_a?(T::Types::TypedSet)
|
33
|
+
Set.new(_convert_to_a(value, type.type, raise_coercion_error))
|
27
34
|
elsif type.is_a?(T::Types::Simple)
|
28
35
|
_convert(value, type.raw_type, raise_coercion_error)
|
29
36
|
elsif type.is_a?(T::Types::Union)
|
@@ -53,7 +60,7 @@ module T::Private
|
|
53
60
|
end
|
54
61
|
elsif type.is_a?(T::Types::TypedHash)
|
55
62
|
unless value.respond_to?(:map)
|
56
|
-
raise
|
63
|
+
raise TypeCoerce::ShapeError.new(value, type)
|
57
64
|
end
|
58
65
|
|
59
66
|
value.map do |k, v|
|
@@ -91,7 +98,7 @@ module T::Private
|
|
91
98
|
SafeType::coerce(value, safe_type_rule)
|
92
99
|
rescue SafeType::EmptyValueError, SafeType::CoercionError
|
93
100
|
if raise_coercion_error
|
94
|
-
raise
|
101
|
+
raise TypeCoerce::CoercionError.new(value, type)
|
95
102
|
else
|
96
103
|
nil
|
97
104
|
end
|
@@ -104,7 +111,7 @@ module T::Private
|
|
104
111
|
return [] if _nil_like?(ary, type)
|
105
112
|
|
106
113
|
unless ary.respond_to?(:map)
|
107
|
-
raise
|
114
|
+
raise TypeCoerce::ShapeError.new(ary, type)
|
108
115
|
end
|
109
116
|
|
110
117
|
ary.map { |value| _convert(value, type, raise_coercion_error) }
|
@@ -115,7 +122,7 @@ module T::Private
|
|
115
122
|
return {} if _nil_like?(args, Hash)
|
116
123
|
|
117
124
|
unless args.respond_to?(:each_pair)
|
118
|
-
raise
|
125
|
+
raise TypeCoerce::ShapeError.new(args, type)
|
119
126
|
end
|
120
127
|
|
121
128
|
props = type.props
|
data/lib/sorbet-coerce.rb
CHANGED
@@ -3,17 +3,17 @@ require_relative 'configuration'
|
|
3
3
|
require 'private/converter'
|
4
4
|
require 'safe_type'
|
5
5
|
|
6
|
-
module
|
6
|
+
module TypeCoerce
|
7
7
|
class CoercionError < SafeType::CoercionError; end
|
8
8
|
class ShapeError < SafeType::CoercionError; end
|
9
9
|
|
10
10
|
define_singleton_method(:[]) do |type|
|
11
|
-
Class.new(
|
11
|
+
Class.new(TypeCoerce::Private::Converter) do
|
12
12
|
define_method(:to_s) { "#{name}#[#{type.to_s}]" }
|
13
13
|
|
14
14
|
define_method(:from) do |args, raise_coercion_error: nil|
|
15
15
|
if raise_coercion_error.nil?
|
16
|
-
raise_coercion_error =
|
16
|
+
raise_coercion_error = TypeCoerce::Configuration.raise_coercion_error
|
17
17
|
end
|
18
18
|
|
19
19
|
T.send('let', send('_convert', args, type, raise_coercion_error), type)
|
data/rbi/sorbet-coerce.rbi
CHANGED
@@ -3,20 +3,20 @@ module SafeType
|
|
3
3
|
class CoercionError < StandardError; end
|
4
4
|
end
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
extend T::Generic
|
6
|
+
module TypeCoerce
|
7
|
+
extend T::Sig
|
8
|
+
extend T::Generic
|
10
9
|
|
11
|
-
|
10
|
+
Elem = type_member
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
sig { params(args: T.untyped, raise_coercion_error: T.nilable(T::Boolean)).returns(Elem) }
|
13
|
+
def from(args, raise_coercion_error: nil); end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
class CoercionError < SafeType::CoercionError; end
|
16
|
+
class ShapeError < SafeType::CoercionError; end
|
17
|
+
end
|
19
18
|
|
19
|
+
module T
|
20
20
|
module Private
|
21
21
|
module Types
|
22
22
|
class TypeAlias
|
data/spec/coerce_spec.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'sorbet-coerce'
|
3
3
|
require 'sorbet-runtime'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe TypeCoerce do
|
6
6
|
context 'when given T::Struct' do
|
7
7
|
class ParamInfo < T::Struct
|
8
8
|
const :name, String
|
@@ -48,7 +48,7 @@ describe T::Coerce do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
let!(:param) {
|
51
|
-
|
51
|
+
TypeCoerce[Param].new.from({
|
52
52
|
id: 1,
|
53
53
|
info: {
|
54
54
|
name: 'mango',
|
@@ -64,7 +64,7 @@ describe T::Coerce do
|
|
64
64
|
}
|
65
65
|
|
66
66
|
let!(:param2) {
|
67
|
-
|
67
|
+
TypeCoerce[Param].new.from({
|
68
68
|
id: '2',
|
69
69
|
info: {
|
70
70
|
name: 'honeydew',
|
@@ -105,7 +105,7 @@ describe T::Coerce do
|
|
105
105
|
expect(param2.opt.notes).to eql []
|
106
106
|
|
107
107
|
expect {
|
108
|
-
|
108
|
+
TypeCoerce[Param].new.from({
|
109
109
|
id: 3,
|
110
110
|
info: {
|
111
111
|
# missing required name
|
@@ -114,8 +114,8 @@ describe T::Coerce do
|
|
114
114
|
})
|
115
115
|
}.to raise_error(ArgumentError)
|
116
116
|
|
117
|
-
expect(
|
118
|
-
expect(
|
117
|
+
expect(TypeCoerce[DefaultParams].new.from(nil).a).to be 1
|
118
|
+
expect(TypeCoerce[DefaultParams].new.from('').a).to be 1
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -127,74 +127,74 @@ describe T::Coerce do
|
|
127
127
|
|
128
128
|
it 'raises an error' do
|
129
129
|
expect {
|
130
|
-
|
130
|
+
TypeCoerce[Param2].new.from({id: 1, info: 1})
|
131
131
|
}.to raise_error(ArgumentError)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
context 'when given primitive types' do
|
136
136
|
it 'reveals the right type' do
|
137
|
-
T.assert_type!(
|
138
|
-
T.assert_type!(
|
139
|
-
T.assert_type!(
|
137
|
+
T.assert_type!(TypeCoerce[Integer].new.from(1), Integer)
|
138
|
+
T.assert_type!(TypeCoerce[Integer].new.from('1.0'), Integer)
|
139
|
+
T.assert_type!(TypeCoerce[T.nilable(Integer)].new.from(nil), T.nilable(Integer))
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'coreces correctly' do
|
143
|
-
expect{
|
144
|
-
expect(
|
145
|
-
expect(
|
146
|
-
expect(
|
143
|
+
expect{TypeCoerce[Integer].new.from(nil)}.to raise_error(TypeError)
|
144
|
+
expect(TypeCoerce[T.nilable(Integer)].new.from(nil) || 1).to eql 1
|
145
|
+
expect(TypeCoerce[Integer].new.from(2)).to eql 2
|
146
|
+
expect(TypeCoerce[Integer].new.from('1.0')).to eql 1
|
147
147
|
|
148
|
-
expect{
|
149
|
-
expect(
|
148
|
+
expect{TypeCoerce[T.nilable(Integer)].new.from('invalid integer string')}.to raise_error(TypeCoerce::CoercionError)
|
149
|
+
expect(TypeCoerce[Float].new.from('1.0')).to eql 1.0
|
150
150
|
|
151
|
-
expect(
|
152
|
-
expect(
|
151
|
+
expect(TypeCoerce[T::Boolean].new.from('false')).to be false
|
152
|
+
expect(TypeCoerce[T::Boolean].new.from('true')).to be true
|
153
153
|
|
154
|
-
expect(
|
155
|
-
expect{
|
156
|
-
expect(
|
154
|
+
expect(TypeCoerce[T.nilable(Integer)].new.from('')).to be nil
|
155
|
+
expect{TypeCoerce[T.nilable(Integer)].new.from([])}.to raise_error(TypeCoerce::CoercionError)
|
156
|
+
expect(TypeCoerce[T.nilable(String)].new.from('')).to eql ''
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
160
|
context 'when given custom types' do
|
161
161
|
it 'coerces correctly' do
|
162
|
-
T.assert_type!(
|
163
|
-
expect(
|
162
|
+
T.assert_type!(TypeCoerce[CustomType].new.from(a: 1), CustomType)
|
163
|
+
expect(TypeCoerce[CustomType].new.from(1).a).to be 1
|
164
164
|
|
165
|
-
expect{
|
165
|
+
expect{TypeCoerce[UnsupportedCustomType].new.from(1)}.to raise_error(ArgumentError)
|
166
166
|
# CustomType2.new(anything) returns Integer 1; 1.is_a?(CustomType2) == false
|
167
|
-
expect{
|
167
|
+
expect{TypeCoerce[CustomType2].new.from(1)}.to raise_error(TypeError)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
context 'when dealing with arries' do
|
172
172
|
it 'coreces correctly' do
|
173
|
-
expect(
|
174
|
-
expect(
|
175
|
-
expect{
|
176
|
-
expect{
|
177
|
-
expect(
|
178
|
-
expect{
|
179
|
-
expect{
|
180
|
-
|
181
|
-
infos =
|
173
|
+
expect(TypeCoerce[T::Array[Integer]].new.from(nil)).to eql []
|
174
|
+
expect(TypeCoerce[T::Array[Integer]].new.from('')).to eql []
|
175
|
+
expect{TypeCoerce[T::Array[Integer]].new.from('not an array')}.to raise_error(TypeCoerce::ShapeError)
|
176
|
+
expect{TypeCoerce[T::Array[Integer]].new.from('1')}.to raise_error(TypeCoerce::ShapeError)
|
177
|
+
expect(TypeCoerce[T::Array[Integer]].new.from(['1', '2', '3'])).to eql [1, 2, 3]
|
178
|
+
expect{TypeCoerce[T::Array[Integer]].new.from(['1', 'invalid', '3'])}.to raise_error(TypeCoerce::CoercionError)
|
179
|
+
expect{TypeCoerce[T::Array[Integer]].new.from({a: 1})}.to raise_error(TypeCoerce::CoercionError)
|
180
|
+
|
181
|
+
infos = TypeCoerce[T::Array[ParamInfo]].new.from([{name: 'a', skill_ids: []}])
|
182
182
|
T.assert_type!(infos, T::Array[ParamInfo])
|
183
183
|
expect(infos.first.name).to eql 'a'
|
184
184
|
|
185
|
-
infos =
|
185
|
+
infos = TypeCoerce[T::Array[ParamInfo]].new.from([{name: 'b', skill_ids: []}])
|
186
186
|
T.assert_type!(infos, T::Array[ParamInfo])
|
187
187
|
expect(infos.first.name).to eql 'b'
|
188
188
|
|
189
189
|
expect {
|
190
|
-
|
190
|
+
TypeCoerce[ParamInfo2].new.from({a: nil, b: nil})
|
191
191
|
}.to raise_error(TypeError)
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
context 'when dealing with hashes'
|
195
|
+
context 'when dealing with hashes' do
|
196
196
|
it 'coreces correctly' do
|
197
|
-
expect(
|
197
|
+
expect(TypeCoerce[T::Hash[String, T::Boolean]].new.from({
|
198
198
|
a: 'true',
|
199
199
|
b: 'false',
|
200
200
|
})).to eql({
|
@@ -202,21 +202,37 @@ describe T::Coerce do
|
|
202
202
|
'b' => false,
|
203
203
|
})
|
204
204
|
|
205
|
-
expect(
|
205
|
+
expect(TypeCoerce[HashParams].new.from({
|
206
206
|
myhash: {'a' => '1', 'b' => '2'},
|
207
207
|
}).myhash).to eql({'a' => 1, 'b' => 2})
|
208
208
|
|
209
209
|
|
210
210
|
expect {
|
211
|
-
|
211
|
+
TypeCoerce[T::Hash[String, T::Boolean]].new.from({
|
212
212
|
a: 'invalid',
|
213
213
|
b: 'false',
|
214
214
|
})
|
215
|
-
}.to raise_error(
|
215
|
+
}.to raise_error(TypeCoerce::CoercionError)
|
216
216
|
|
217
217
|
expect {
|
218
|
-
|
219
|
-
}.to raise_error(
|
218
|
+
TypeCoerce[T::Hash[String, Integer]].new.from(1)
|
219
|
+
}.to raise_error(TypeCoerce::ShapeError)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'when dealing with sets' do
|
224
|
+
it 'coreces correctly' do
|
225
|
+
expect(TypeCoerce[T::Set[Integer]].new.from(
|
226
|
+
Set.new(['1', '2', '3'])
|
227
|
+
)).to eq Set.new([1, 2, 3])
|
228
|
+
|
229
|
+
expect {
|
230
|
+
TypeCoerce[T::Set[Integer]].new.from(Set.new(['1', 'invalid', '3']))
|
231
|
+
}.to raise_error(TypeCoerce::CoercionError)
|
232
|
+
|
233
|
+
expect {
|
234
|
+
TypeCoerce[T::Set[Integer]].new.from(1)
|
235
|
+
}.to raise_error(TypeCoerce::ShapeError)
|
220
236
|
end
|
221
237
|
end
|
222
238
|
|
@@ -224,7 +240,14 @@ describe T::Coerce do
|
|
224
240
|
MyType = T.type_alias(T::Boolean)
|
225
241
|
|
226
242
|
it 'coerces correctly' do
|
227
|
-
expect(
|
243
|
+
expect(TypeCoerce[MyType].new.from('false')).to be false
|
228
244
|
end
|
229
245
|
end
|
246
|
+
|
247
|
+
it 'works with T.untyped' do
|
248
|
+
expect(TypeCoerce[T.untyped].new.from(1)).to eql 1
|
249
|
+
|
250
|
+
obj = CustomType.new(1)
|
251
|
+
expect(TypeCoerce[T::Hash[String, T.untyped]].new.from({a: obj})).to eq({'a' => obj})
|
252
|
+
end
|
230
253
|
end
|
data/spec/nested_spec.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'sorbet-coerce'
|
3
3
|
require 'sorbet-runtime'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe TypeCoerce do
|
6
6
|
context 'when given nested types' do
|
7
7
|
class User < T::Struct
|
8
8
|
const :id, Integer
|
@@ -15,7 +15,7 @@ describe T::Coerce do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'works with nest T::Struct' do
|
18
|
-
converted =
|
18
|
+
converted = TypeCoerce[NestedParam].new.from({
|
19
19
|
users: [{id: '1'}],
|
20
20
|
params: {
|
21
21
|
users: [{id: '2', valid: 'true'}],
|
@@ -42,16 +42,16 @@ describe T::Coerce do
|
|
42
42
|
|
43
43
|
it 'works with nest T::Array' do
|
44
44
|
expect {
|
45
|
-
|
46
|
-
}.to raise_error(
|
45
|
+
TypeCoerce[T::Array[T.nilable(Integer)]].new.from(['1', 'invalid', '3'])
|
46
|
+
}.to raise_error(TypeCoerce::CoercionError)
|
47
47
|
expect(
|
48
|
-
|
48
|
+
TypeCoerce[T::Array[T::Array[Integer]]].new.from([nil])
|
49
49
|
).to eql([[]])
|
50
50
|
expect(
|
51
|
-
|
51
|
+
TypeCoerce[T::Array[T::Array[Integer]]].new.from([['1'], ['2'], ['3']]),
|
52
52
|
).to eql [[1], [2], [3]]
|
53
53
|
|
54
|
-
expect(
|
54
|
+
expect(TypeCoerce[
|
55
55
|
T::Array[
|
56
56
|
T::Array[
|
57
57
|
T::Array[User]
|
@@ -59,7 +59,7 @@ describe T::Coerce do
|
|
59
59
|
]
|
60
60
|
].new.from([[[{id: '1'}]]]).flatten.first.id).to eql(1)
|
61
61
|
|
62
|
-
expect(
|
62
|
+
expect(TypeCoerce[
|
63
63
|
T::Array[
|
64
64
|
T::Array[
|
65
65
|
T::Array[
|
@@ -71,7 +71,7 @@ describe T::Coerce do
|
|
71
71
|
]
|
72
72
|
].new.from([[[[[{id: 1}]]]]]).flatten.first.id).to eql 1
|
73
73
|
|
74
|
-
expect(
|
74
|
+
expect(TypeCoerce[
|
75
75
|
T.nilable(T::Array[T.nilable(T::Array[T.nilable(User)])])
|
76
76
|
].new.from([[{id: '1'}]]).flatten.map(&:id)).to eql([1])
|
77
77
|
end
|
data/spec/soft_error_spec.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
require 'sorbet-coerce'
|
3
3
|
require 'sorbet-runtime'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe TypeCoerce do
|
6
6
|
context 'when type errors are soft errors' do
|
7
7
|
let(:ignore_error) { Proc.new {} }
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
allow(
|
10
|
+
allow(TypeCoerce::Configuration).to receive(
|
11
11
|
:raise_coercion_error,
|
12
12
|
).and_return(false)
|
13
13
|
|
@@ -42,24 +42,24 @@ describe T::Coerce do
|
|
42
42
|
|
43
43
|
it 'overwrites the global config when inline config is set' do
|
44
44
|
expect {
|
45
|
-
|
46
|
-
}.to raise_error(
|
45
|
+
TypeCoerce[Integer].new.from(invalid_arg, raise_coercion_error: true)
|
46
|
+
}.to raise_error(TypeCoerce::CoercionError)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'works as expected' do
|
50
|
-
expect(
|
50
|
+
expect(TypeCoerce[Integer].new.from(invalid_arg)).to eql(nil)
|
51
51
|
|
52
|
-
expect{
|
53
|
-
expect(
|
52
|
+
expect{TypeCoerce[T::Array[Integer]].new.from(1)}.to raise_error(TypeCoerce::ShapeError)
|
53
|
+
expect(TypeCoerce[T::Array[Integer]].new.from({a: 1})).to eql([nil])
|
54
54
|
|
55
55
|
expect {
|
56
|
-
|
56
|
+
TypeCoerce[CustomTypeRaisesHardError].new.from(1)
|
57
57
|
}.to raise_error(StandardError)
|
58
|
-
expect(
|
58
|
+
expect(TypeCoerce[CustomTypeDoesNotRiaseHardError].new.from(1)).to eql(1)
|
59
59
|
|
60
60
|
sorbet_version = Gem.loaded_specs['sorbet-runtime'].version
|
61
61
|
if sorbet_version >= Gem::Version.new('0.4.4948')
|
62
|
-
expect(
|
62
|
+
expect(TypeCoerce[ParamsWithSortError].new.from({a: invalid_arg}).a).to eql(nil)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/spec/sorbet_test_cases.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# typed: true
|
2
2
|
require 'sorbet-coerce'
|
3
3
|
|
4
|
-
T.assert_type!(
|
4
|
+
T.assert_type!(TypeCoerce[Integer].new.from('1'), Integer)
|
5
5
|
T.assert_type!(
|
6
|
-
|
6
|
+
TypeCoerce[T.nilable(Integer)].new.from('invalid', raise_coercion_error: false),
|
7
7
|
T.nilable(Integer),
|
8
8
|
)
|
9
9
|
|
10
|
-
|
10
|
+
TypeCoerce::Configuration.raise_coercion_error = true
|
11
11
|
coercion_error = nil
|
12
12
|
begin
|
13
|
-
|
14
|
-
rescue
|
13
|
+
TypeCoerce[T.nilable(Integer)].new.from('invalid')
|
14
|
+
rescue TypeCoerce::CoercionError => e
|
15
15
|
coercion_error = e
|
16
16
|
end
|
17
17
|
raise 'no coercion error is raised' unless coercion_error
|
18
18
|
|
19
19
|
T.assert_type!(
|
20
|
-
|
20
|
+
TypeCoerce[T.nilable(Integer)].new.from('invalid', raise_coercion_error: false),
|
21
21
|
T.nilable(Integer),
|
22
22
|
)
|