Skip to content

Commit bddb3e9

Browse files
authored
chore(test): remove assertType (#5420)
1 parent 288cdd5 commit bddb3e9

File tree

8 files changed

+49
-73
lines changed

8 files changed

+49
-73
lines changed

packages/effect/dtslint/Effect.tst.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Either, Types } from "effect"
22
import { Array as Arr, Context, Effect, hole, Option, pipe, Predicate, Schedule } from "effect"
33
import type { NonEmptyArray, NonEmptyReadonlyArray } from "effect/Array"
44
import type { Cause, NoSuchElementException, UnknownException } from "effect/Cause"
5+
import type { Exit } from "effect/Exit"
56
import { describe, expect, it, when } from "tstyche"
67

78
class TestError1 {
@@ -629,6 +630,20 @@ describe("Effect", () => {
629630
).type.toBe<Effect.Effect<number, TestError1 | TestError2>>()
630631
})
631632

633+
it("catchIf", () => {
634+
expect(pipe(
635+
Effect.fail<TestError1 | Error>(new TestError1()),
636+
Effect.catchIf(
637+
(error) => {
638+
expect(error).type.toBe<TestError1 | Error>()
639+
return true
640+
},
641+
Effect.succeed
642+
),
643+
Effect.exit
644+
)).type.toBe<Effect.Effect<Exit<Error | TestError1, Error | TestError1>, never, never>>()
645+
})
646+
632647
it("catchTag", () => {
633648
expect(Effect.catchTag).type.not.toBeCallableWith(
634649
hole<Effect.Effect<number, TestError1>>(),

packages/effect/dtslint/Match.tst.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,34 @@ describe("Match", () => {
233233
})
234234
)
235235
).type.toBe<number>()
236+
237+
const match = pipe(
238+
Match.type<Uint8Array | Uint16Array>(),
239+
Match.when(Match.instanceOf(Uint8Array), (v) => {
240+
// @tstyche if { target: [">=5.7"] } -- Before TypeScript 5.7, 'Uint8Array' was not generic
241+
expect(v).type.toBe<Uint8Array<ArrayBuffer>>()
242+
// @tstyche if { target: ["<5.7"] }
243+
expect(v).type.toBe<Uint8Array>()
244+
return "uint8"
245+
}),
246+
Match.when(Match.instanceOf(Uint16Array), (v) => {
247+
// @tstyche if { target: [">=5.7"] } -- Before TypeScript 5.7, 'Uint16Array' was not generic
248+
expect(v).type.toBe<Uint16Array<ArrayBuffer>>()
249+
// @tstyche if { target: ["<5.7"] }
250+
expect(v).type.toBe<Uint16Array>()
251+
return "uint16"
252+
}),
253+
Match.orElse((v) => {
254+
// @tstyche if { target: [">=5.7"] } -- Before TypeScript 5.7, 'Uint8Array' and 'Uint16Array' were not generic
255+
expect(v).type.toBe<Uint8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike>>()
256+
// @tstyche if { target: ["<5.7"] }
257+
expect(v).type.toBe<Uint8Array | Uint16Array>()
258+
return "a"
259+
})
260+
)
261+
262+
expect(match(new Uint8Array())).type.toBe<string>()
263+
expect(match(new Uint16Array())).type.toBe<string>()
236264
})
237265

238266
it("instanceOf prop", () => {

packages/effect/dtslint/Option.tst.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ declare const string: Option.Option<string>
66
declare const numberOrString: Option.Option<string | number>
77

88
declare const primitiveNumber: number
9-
declare const primitiveNumerOrString: string | number
9+
declare const primitiveNumberOrString: string | number
1010
declare const predicateNumbersOrStrings: Predicate.Predicate<number | string>
1111

1212
describe("Option", () => {
1313
it("liftPredicate", () => {
1414
expect(
15-
Option.liftPredicate(primitiveNumerOrString, Predicate.isString)
15+
Option.liftPredicate(primitiveNumberOrString, Predicate.isString)
1616
).type.toBe<Option.Option<string>>()
1717
expect(
18-
pipe(primitiveNumerOrString, Option.liftPredicate(Predicate.isString))
18+
pipe(primitiveNumberOrString, Option.liftPredicate(Predicate.isString))
1919
).type.toBe<Option.Option<string>>()
2020

2121
expect(
2222
Option.liftPredicate(
23-
primitiveNumerOrString,
23+
primitiveNumberOrString,
2424
(n): n is number => {
2525
expect(n).type.toBe<string | number>()
2626
return typeof n === "number"
@@ -29,7 +29,7 @@ describe("Option", () => {
2929
).type.toBe<Option.Option<number>>()
3030
expect(
3131
pipe(
32-
primitiveNumerOrString,
32+
primitiveNumberOrString,
3333
Option.liftPredicate(
3434
(n): n is number => {
3535
expect(n).type.toBe<string | number>()

packages/effect/test/Effect/error-handling.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as FiberId from "effect/FiberId"
1111
import { constFalse, constTrue, identity, pipe } from "effect/Function"
1212
import * as Option from "effect/Option"
1313
import { causesArb } from "../utils/cause.js"
14-
import { assertType, satisfies } from "../utils/types.js"
1514

1615
const ExampleError = new Error("Oh noes!")
1716

@@ -269,7 +268,6 @@ describe("Effect", () => {
269268
Effect.exit
270269
)
271270
deepStrictEqual(result, Exit.fail({ _tag: "ErrorB" as const }))
272-
satisfies<true>(assertType<Exit.Exit<ErrorA, ErrorB>>()(result))
273271
}))
274272
it.effect("catchTags - recovers from one of several tagged errors", () =>
275273
Effect.gen(function*() {

packages/effect/test/Effect/structural.test.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,41 @@ import * as Effect from "effect/Effect"
44
import * as Either from "effect/Either"
55
import { pipe } from "effect/Function"
66
import * as Option from "effect/Option"
7-
import { assertType, satisfies } from "../utils/types.js"
87

98
describe("Effect", () => {
109
describe("all", () => {
1110
it.effect("should work with one array argument", () =>
1211
Effect.gen(function*() {
1312
const res = yield* (Effect.all([Effect.succeed(0), Effect.succeed(1)]))
1413
deepStrictEqual(res, [0, 1])
15-
satisfies<true>(assertType<[number, number]>()(res))
1614
}))
1715
it.effect("should work with one empty array argument", () =>
1816
Effect.gen(function*() {
1917
const x = yield* (Effect.all([]))
2018
deepStrictEqual(x, [])
21-
satisfies<true>(assertType<[]>()(x))
2219
}))
2320
it.effect("should work with an array argument", () =>
2421
Effect.gen(function*() {
2522
const y = Effect.all([0, 1, 2].map((n) => Effect.succeed(n + 1)))
2623
const x = yield* y
2724
deepStrictEqual(x, [1, 2, 3])
28-
satisfies<true>(assertType<Array<number>>()(x))
2925
}))
3026
it.effect("should work with one record argument", () =>
3127
Effect.gen(function*() {
3228
const result = yield* (Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) }))
3329
const { a, b } = result
3430
deepStrictEqual(a, 0)
3531
deepStrictEqual(b, 1)
36-
satisfies<true>(
37-
assertType<{
38-
readonly a: number
39-
readonly b: number
40-
}>()(result)
41-
)
4232
}))
4333
it.effect("should work with one iterable argument", () =>
4434
Effect.gen(function*() {
4535
const result = yield* (Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)])))
4636
deepStrictEqual(result, [0, 1])
47-
satisfies<true>(assertType<Array<number>>()(result))
4837
}))
4938
it.effect("should work with one empty record", () =>
5039
Effect.gen(function*() {
5140
const x = yield* (Effect.all({}))
5241
deepStrictEqual(x, {})
53-
satisfies<true>(assertType<{}>()(x))
5442
}))
5543
})
5644
describe("all/ concurrency", () => {
@@ -60,15 +48,13 @@ describe("Effect", () => {
6048
concurrency: "unbounded"
6149
}))
6250
deepStrictEqual(res, [0, 1])
63-
satisfies<true>(assertType<[number, number]>()(res))
6451
}))
6552
it.effect("should work with one empty array argument", () =>
6653
Effect.gen(function*() {
6754
const x = yield* (Effect.all([], {
6855
concurrency: "unbounded"
6956
}))
7057
deepStrictEqual(x, [])
71-
satisfies<true>(assertType<[]>()(x))
7258
}))
7359
it.effect("should work with one record argument", () =>
7460
Effect.gen(function*() {
@@ -78,45 +64,30 @@ describe("Effect", () => {
7864
const { a, b } = result
7965
deepStrictEqual(a, 0)
8066
deepStrictEqual(b, 1)
81-
satisfies<true>(
82-
assertType<{
83-
a: number
84-
b: number
85-
}>()(result)
86-
)
8767
}))
8868
it.effect("should work with one empty record", () =>
8969
Effect.gen(function*() {
9070
const x = yield* (Effect.all({}, { concurrency: "unbounded" }))
9171
deepStrictEqual(x, {})
92-
satisfies<true>(assertType<{}>()(x))
9372
}))
9473
})
9574
describe("all/ validate mode", () => {
9675
it.effect("should work with one array argument", () =>
9776
Effect.gen(function*() {
9877
const res = yield* (Effect.all([Effect.succeed(0), Effect.succeed(1)], { mode: "validate" }))
9978
deepStrictEqual(res, [0, 1])
100-
satisfies<true>(assertType<[number, number]>()(res))
10179
}))
10280
it.effect("failure should work with one array argument", () =>
10381
Effect.gen(function*() {
10482
const res = yield* (Effect.flip(Effect.all([Effect.fail(0), Effect.succeed(1)], { mode: "validate" })))
10583
deepStrictEqual(res, [Option.some(0), Option.none()])
106-
satisfies<true>(assertType<[Option.Option<number>, Option.Option<never>]>()(res))
10784
}))
10885
it.effect("should work with one record argument", () =>
10986
Effect.gen(function*() {
11087
const result = yield* (Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) }, { mode: "validate" }))
11188
const { a, b } = result
11289
deepStrictEqual(a, 0)
11390
deepStrictEqual(b, 1)
114-
satisfies<true>(
115-
assertType<{
116-
readonly a: number
117-
readonly b: number
118-
}>()(result)
119-
)
12091
}))
12192
it.effect("failure should work with one record argument", () =>
12293
Effect.gen(function*() {
@@ -126,45 +97,30 @@ describe("Effect", () => {
12697
const { a, b } = result
12798
assertSome(a, 0)
12899
assertNone(b)
129-
satisfies<true>(
130-
assertType<{
131-
readonly a: Option.Option<number>
132-
readonly b: Option.Option<never>
133-
}>()(result)
134-
)
135100
}))
136101
it.effect("should work with one iterable argument", () =>
137102
Effect.gen(function*() {
138103
const result = yield* (Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]), { mode: "validate" }))
139104
deepStrictEqual(result, [0, 1])
140-
satisfies<true>(assertType<Array<number>>()(result))
141105
}))
142106
})
143107
describe("all/ either mode", () => {
144108
it.effect("should work with one array argument", () =>
145109
Effect.gen(function*() {
146110
const res = yield* (Effect.all([Effect.succeed(0), Effect.succeed(1)], { mode: "either" }))
147111
deepStrictEqual(res, [Either.right(0), Either.right(1)])
148-
satisfies<true>(assertType<[Either.Either<number>, Either.Either<number>]>()(res))
149112
}))
150113
it.effect("failure should work with one array argument", () =>
151114
Effect.gen(function*() {
152115
const res = yield* (Effect.all([Effect.fail(0), Effect.succeed(1)], { mode: "either" }))
153116
deepStrictEqual(res, [Either.left(0), Either.right(1)])
154-
satisfies<true>(assertType<[Either.Either<never, number>, Either.Either<number>]>()(res))
155117
}))
156118
it.effect("should work with one record argument", () =>
157119
Effect.gen(function*() {
158120
const result = yield* (Effect.all({ a: Effect.succeed(0), b: Effect.succeed(1) }, { mode: "either" }))
159121
const { a, b } = result
160122
assertRight(a, 0)
161123
assertRight(b, 1)
162-
satisfies<true>(
163-
assertType<{
164-
readonly a: Either.Either<number>
165-
readonly b: Either.Either<number>
166-
}>()(result)
167-
)
168124
}))
169125
it.effect("failure should work with one record argument", () =>
170126
Effect.gen(function*() {
@@ -174,18 +130,11 @@ describe("Effect", () => {
174130
const { a, b } = result
175131
assertLeft(a, 0)
176132
assertRight(b, 1)
177-
satisfies<true>(
178-
assertType<{
179-
readonly a: Either.Either<never, number>
180-
readonly b: Either.Either<number>
181-
}>()(result)
182-
)
183133
}))
184134
it.effect("should work with one iterable argument", () =>
185135
Effect.gen(function*() {
186136
const result = yield* (Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]), { mode: "either" }))
187137
deepStrictEqual(result, [Either.right(0), Either.right(1)])
188-
satisfies<true>(assertType<Array<Either.Either<number>>>()(result))
189138
}))
190139
})
191140
describe("allWith", () => {
@@ -196,7 +145,6 @@ describe("Effect", () => {
196145
Effect.allWith()
197146
)
198147
deepStrictEqual(res, [0, 1])
199-
satisfies<true>(assertType<[number, number]>()(res))
200148
}))
201149
})
202150
})

packages/effect/test/Match.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
throws
1212
} from "@effect/vitest/utils"
1313
import { Either, Match as M, Option, pipe, Predicate } from "effect"
14-
import { assertType } from "./utils/types.js"
1514

1615
describe("Match", () => {
1716
it("TypeMatcher.pipe() method", () => {
@@ -571,16 +570,12 @@ describe("Match", () => {
571570
})
572571

573572
it("instanceOf", () => {
574-
// These type-level tests cannot be moved to a dtslint test because
575-
// of the difference in the way the type is retrieved in ts 5.7
576573
const match = pipe(
577574
M.type<Uint8Array | Uint16Array>(),
578575
M.when(M.instanceOf(Uint8Array), (_) => {
579-
assertType<Uint8Array>()(_) satisfies true
580576
return "uint8"
581577
}),
582578
M.when(M.instanceOf(Uint16Array), (_) => {
583-
assertType<Uint16Array>()(_) satisfies true
584579
return "uint16"
585580
}),
586581
M.orElse((_) => {

packages/effect/test/Option.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertType, describe, it } from "@effect/vitest"
1+
import { describe, it } from "@effect/vitest"
22
import {
33
assertFalse,
44
assertNone,
@@ -473,16 +473,12 @@ describe("Option", () => {
473473
})
474474

475475
it("all/ tuple", () => {
476-
assertType<Option.Option<[number, string]>>(Option.all([Option.some(1), Option.some("hello")]))
477476
assertSome(Option.all([]), [])
478477
assertSome(Option.all([Option.some(1), Option.some("hello")]), [1, "hello"])
479478
assertNone(Option.all([Option.some(1), Option.none()]))
480479
})
481480

482481
it("all/ iterable", () => {
483-
assertType<Option.Option<Array<number>>>(Option.all([Option.some(1), Option.some(2)]))
484-
assertType<Option.Option<Array<number>>>(Option.all(new Set([Option.some(1), Option.some(2)])))
485-
486482
assertSome(Option.all([]), [])
487483
assertNone(Option.all([Option.none()]))
488484
assertSome(Option.all([Option.some(1), Option.some(2)]), [1, 2])
@@ -491,7 +487,6 @@ describe("Option", () => {
491487
})
492488

493489
it("all/ struct", () => {
494-
assertType<Option.Option<{ a: number; b: string }>>(Option.all({ a: Option.some(1), b: Option.some("hello") }))
495490
assertSome(
496491
Option.all({ a: Option.some(1), b: Option.some("hello") }),
497492
{ a: 1, b: "hello" }

packages/effect/test/utils/types.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)