Skip to content

Commit bdaf804

Browse files
committed
undeprecate RefinementC, refinement, Integer
1 parent 4b85202 commit bdaf804

File tree

8 files changed

+45
-65
lines changed

8 files changed

+45
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- undeprecate `FunctionType`, `FunctionC`, `Function`
2020
- undeprecate `NeverType`, `NeverC`, `never`
2121
- undeprecate `AnyType`, `AnyC`, `any`
22+
- undeprecate `RefinementC`, `refinement`, `Integer`
2223

2324
# 2.2.19
2425

src/index.ts

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,6 @@ export function brand<C extends Any, N extends string, B extends { readonly [K i
11571157
predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>,
11581158
name: N
11591159
): BrandC<C, B> {
1160-
// tslint:disable-next-line: deprecation
11611160
return refinement(codec, predicate, name)
11621161
}
11631162

@@ -2062,6 +2061,43 @@ export interface AnyC extends AnyType {}
20622061
*/
20632062
export const any: AnyC = new AnyType()
20642063

2064+
/**
2065+
* @since 1.5.3
2066+
*/
2067+
export interface RefinementC<C extends Any> extends RefinementType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
2068+
2069+
/**
2070+
* @category combinators
2071+
* @since 1.0.0
2072+
*/
2073+
export function refinement<C extends Any>(
2074+
codec: C,
2075+
predicate: Predicate<TypeOf<C>>,
2076+
name = `(${codec.name} | ${getFunctionName(predicate)})`
2077+
): RefinementC<C> {
2078+
return new RefinementType(
2079+
name,
2080+
(u): u is TypeOf<C> => codec.is(u) && predicate(u),
2081+
(i, c) => {
2082+
const e = codec.validate(i, c)
2083+
if (isLeft(e)) {
2084+
return e
2085+
}
2086+
const a = e.right
2087+
return predicate(a) ? success(a) : failure(a, c)
2088+
},
2089+
codec.encode,
2090+
codec,
2091+
predicate
2092+
)
2093+
}
2094+
2095+
/**
2096+
* @category primitives
2097+
* @since 1.0.0
2098+
*/
2099+
export const Integer = refinement(number, Number.isInteger, 'Integer')
2100+
20652101
// -------------------------------------------------------------------------------------
20662102
// deprecated
20672103
// -------------------------------------------------------------------------------------
@@ -2215,54 +2251,6 @@ export interface ObjectC extends ObjectType {}
22152251
// tslint:disable-next-line: deprecation
22162252
export const object: ObjectC = new ObjectType()
22172253

2218-
/**
2219-
* Use `BrandC` instead.
2220-
*
2221-
* @since 1.5.3
2222-
* @deprecated
2223-
*/
2224-
export interface RefinementC<C extends Any> extends RefinementType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
2225-
2226-
/**
2227-
* Use `brand` instead.
2228-
*
2229-
* @category combinators
2230-
* @since 1.0.0
2231-
* @deprecated
2232-
*/
2233-
export function refinement<C extends Any>(
2234-
codec: C,
2235-
predicate: Predicate<TypeOf<C>>,
2236-
name = `(${codec.name} | ${getFunctionName(predicate)})`
2237-
): // tslint:disable-next-line: deprecation
2238-
RefinementC<C> {
2239-
return new RefinementType(
2240-
name,
2241-
(u): u is TypeOf<C> => codec.is(u) && predicate(u),
2242-
(i, c) => {
2243-
const e = codec.validate(i, c)
2244-
if (isLeft(e)) {
2245-
return e
2246-
}
2247-
const a = e.right
2248-
return predicate(a) ? success(a) : failure(a, c)
2249-
},
2250-
codec.encode,
2251-
codec,
2252-
predicate
2253-
)
2254-
}
2255-
2256-
/**
2257-
* Use `Int` instead.
2258-
*
2259-
* @category primitives
2260-
* @since 1.0.0
2261-
* @deprecated
2262-
*/
2263-
// tslint:disable-next-line: deprecation
2264-
export const Integer = refinement(number, Number.isInteger, 'Integer')
2265-
22662254
/**
22672255
* Use `record` instead.
22682256
*

test/2.1.x/default-types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ describe('bigint', () => {
139139

140140
describe('Integer', () => {
141141
it('should validate integers', () => {
142-
// tslint:disable-next-line: deprecation
143142
const T = t.Integer
144143
assertSuccess(T.decode(1))
145144
assertFailure(T, 0.5, ['Invalid value 0.5 supplied to : Integer'])

test/2.1.x/exact.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe('exact', () => {
5252
})
5353

5454
it('should succeed validating a valid value (refinement)', () => {
55-
// tslint:disable-next-line: deprecation
5655
const T = t.exact(t.refinement(t.type({ foo: t.string }), (p) => p.foo.length > 2))
5756
assertSuccess(T.decode({ foo: 'foo' }))
5857
})
@@ -107,14 +106,12 @@ describe('exact', () => {
107106
})
108107

109108
it('should fail validating an invalid value (refinement)', () => {
110-
// tslint:disable-next-line: deprecation
111109
const T = t.exact(t.refinement(t.type({ foo: t.string }), (p) => p.foo.length > 2))
112110
assertFailure(T, null, ['Invalid value null supplied to : Exact<({ foo: string } | <function1>)>'])
113111
assertFailure(T, { foo: 'a' }, ['Invalid value {"foo":"a"} supplied to : Exact<({ foo: string } | <function1>)>'])
114112
})
115113

116114
it('should strip additional properties (refinement)', () => {
117-
// tslint:disable-next-line: deprecation
118115
const T = t.exact(t.refinement(t.type({ foo: t.string }), (p) => p.foo.length > 2))
119116
assertSuccess(T.decode({ foo: 'foo', bar: 1 }), { foo: 'foo' })
120117
})

test/2.1.x/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as t from '../../src/index'
44
import { PathReporter } from '../../src/PathReporter'
55
import { pipe } from 'fp-ts/lib/pipeable'
66

7+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
78
export function assertStrictEqual<T>(result: t.Validation<T>, expected: any): void {
89
pipe(
910
result,
@@ -95,7 +96,6 @@ export const HyphenatedString = new t.Type<string, string, unknown>(
9596
(a) => a[0] + a[2]
9697
)
9798

98-
// tslint:disable-next-line: deprecation
9999
export const IntegerFromString = t.refinement(NumberFromString, t.Integer.is, 'IntegerFromString')
100100

101101
export function withDefault<T extends t.Mixed>(

test/2.1.x/record.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ describe('record', () => {
150150
const value1 = { aa: 1 }
151151
assertStrictEqual(T1.decode(value1), value1)
152152
const T2 = t.record(
153-
// tslint:disable-next-line: deprecation
154153
t.refinement(t.string, (s) => s.length >= 2),
155154
t.number
156155
)

test/2.1.x/refinement.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,25 @@ import { assertSuccess, assertFailure, assertStrictEqual, IntegerFromString, Num
55
describe('refinement', () => {
66
describe('name', () => {
77
it('should assign a default name', () => {
8-
// tslint:disable-next-line: deprecation
98
const T = t.refinement(t.number, (n) => n >= 0)
109
assert.strictEqual(T.name, '(number | <function1>)')
1110
})
1211

1312
it('should accept a name', () => {
14-
// tslint:disable-next-line: deprecation
1513
const T = t.refinement(t.number, (n) => n >= 0, 'T')
1614
assert.strictEqual(T.name, 'T')
1715
})
1816
})
1917

2018
describe('is', () => {
2119
it('should check a isomorphic value', () => {
22-
// tslint:disable-next-line: deprecation
2320
const T = t.Integer
2421
assert.strictEqual(T.is(1.2), false)
2522
assert.strictEqual(T.is('a'), false)
2623
assert.strictEqual(T.is(1), true)
2724
})
2825

2926
it('should check a prismatic value', () => {
30-
// tslint:disable-next-line: deprecation
3127
const T = t.refinement(NumberFromString, (n) => n % 1 === 0)
3228
assert.strictEqual(T.is(1.2), false)
3329
assert.strictEqual(T.is('a'), false)
@@ -37,21 +33,22 @@ describe('refinement', () => {
3733

3834
describe('decode', () => {
3935
it('should succeed validating a valid value', () => {
40-
// tslint:disable-next-line: deprecation
4136
const T = t.refinement(t.number, (n) => n >= 0)
4237
assertSuccess(T.decode(0))
4338
assertSuccess(T.decode(1))
4439
})
4540

4641
it('should return the same reference if validation succeeded', () => {
47-
// tslint:disable-next-line: deprecation
48-
const T = t.refinement(t.Dictionary, () => true)
42+
const T = t.refinement(
43+
// tslint:disable-next-line: deprecation
44+
t.Dictionary,
45+
() => true
46+
)
4947
const value = {}
5048
assertStrictEqual(T.decode(value), value)
5149
})
5250

5351
it('should fail validating an invalid value', () => {
54-
// tslint:disable-next-line: deprecation
5552
const T = t.Integer
5653
assertFailure(T, 'a', ['Invalid value "a" supplied to : Integer'])
5754
assertFailure(T, 1.2, ['Invalid value 1.2 supplied to : Integer'])
@@ -66,13 +63,11 @@ describe('refinement', () => {
6663

6764
describe('encode', () => {
6865
it('should encode a prismatic value', () => {
69-
// tslint:disable-next-line: deprecation
7066
const T = t.refinement(t.array(NumberFromString), () => true)
7167
assert.deepStrictEqual(T.encode([1]), ['1'])
7268
})
7369

7470
it('should return the same reference while encoding', () => {
75-
// tslint:disable-next-line: deprecation
7671
const T = t.refinement(t.array(t.number), () => true)
7772
assert.strictEqual(T.encode, t.identity)
7873
})

test/2.1.x/union.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ describe('union', () => {
199199
}
200200
)
201201
assert.strictEqual(
202+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
202203
// @ts-expect-error
203204
t.getTags(t.intersection([t.type({ a: t.literal('a') }), t.type({ a: t.literal('b') })])),
204205
t.emptyTags

0 commit comments

Comments
 (0)