🔥 Drop redundant not.toBeAny assertions in the fixture
The exact-equality `toEqualTypeOf` assertions already reject `any`, so the `.not.toBeAny()` guards were redundant. Refresh the fixture header and development/ci.md to match.
This commit is contained in:
1 parent
ebe58a9167
commit
24cc007ab0
2 files changed
+9
-21
No files matched your search
+6
-18
@@ -6,12 +6,12 @@
|
|||||||
//
|
//
|
||||||
// Why the `expectTypeOf` assertions: a compile that merely succeeds is a weak
|
// Why the `expectTypeOf` assertions: a compile that merely succeeds is a weak
|
||||||
// oracle. An `any`-typed declaration would compile, but `expect-type`'s exact
|
// oracle. An `any`-typed declaration would compile, but `expect-type`'s exact
|
||||||
// equality and `.not.toBeAny()` reject `any`, so the assertions prove the
|
// equality rejects `any`, so the assertions prove the emitted types are real.
|
||||||
// emitted types are real. Every handler *parameter* is asserted too, not just
|
// Every handler *parameter* is asserted too, not just the matcher: the handler's
|
||||||
// the matcher: the handler's member type comes from the `Member` inversion in
|
// member type comes from the `Member` inversion in the declarations, and a wrong
|
||||||
// the declarations, and a wrong or `any` parameter would otherwise slip
|
// or `any` parameter would otherwise slip through, since the matcher's own
|
||||||
// through, since the matcher's own `(shape: T) => R` type is built from `T` and
|
// `(shape: T) => R` type is built from `T` and the handler returns. See
|
||||||
// the handler returns. See development/ci.md § TypeScript compatibility.
|
// development/ci.md § TypeScript compatibility.
|
||||||
|
|
||||||
import { expectTypeOf } from "expect-type";
|
import { expectTypeOf } from "expect-type";
|
||||||
import {
|
import {
|
||||||
@@ -25,37 +25,31 @@ type ResultCode = "ok" | "created";
|
|||||||
|
|
||||||
const toStatus = getPrimitiveUnionMatcher<ResultCode>()({
|
const toStatus = getPrimitiveUnionMatcher<ResultCode>()({
|
||||||
ok: (s) => {
|
ok: (s) => {
|
||||||
expectTypeOf(s).not.toBeAny();
|
|
||||||
expectTypeOf(s).toEqualTypeOf<"ok">();
|
expectTypeOf(s).toEqualTypeOf<"ok">();
|
||||||
return "OK";
|
return "OK";
|
||||||
},
|
},
|
||||||
created: (s) => {
|
created: (s) => {
|
||||||
expectTypeOf(s).not.toBeAny();
|
|
||||||
expectTypeOf(s).toEqualTypeOf<"created">();
|
expectTypeOf(s).toEqualTypeOf<"created">();
|
||||||
return "CREATED";
|
return "CREATED";
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expectTypeOf(toStatus).not.toBeAny();
|
|
||||||
expectTypeOf(toStatus).toEqualTypeOf<(shape: ResultCode) => string>();
|
expectTypeOf(toStatus).toEqualTypeOf<(shape: ResultCode) => string>();
|
||||||
|
|
||||||
// The widening twin keeps each handler's own return type in the union.
|
// The widening twin keeps each handler's own return type in the union.
|
||||||
const toStatusW = getPrimitiveUnionMatcherW<ResultCode>()(
|
const toStatusW = getPrimitiveUnionMatcherW<ResultCode>()(
|
||||||
{
|
{
|
||||||
ok: (s) => {
|
ok: (s) => {
|
||||||
expectTypeOf(s).not.toBeAny();
|
|
||||||
expectTypeOf(s).toEqualTypeOf<"ok">();
|
expectTypeOf(s).toEqualTypeOf<"ok">();
|
||||||
return "OK" as const;
|
return "OK" as const;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
(rest) => {
|
(rest) => {
|
||||||
expectTypeOf(rest).not.toBeAny();
|
|
||||||
expectTypeOf(rest).toEqualTypeOf<"created">();
|
expectTypeOf(rest).toEqualTypeOf<"created">();
|
||||||
return "CREATED" as const;
|
return "CREATED" as const;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
expectTypeOf(toStatusW).not.toBeAny();
|
|
||||||
expectTypeOf(toStatusW).toEqualTypeOf<
|
expectTypeOf(toStatusW).toEqualTypeOf<
|
||||||
(shape: ResultCode) => "OK" | "CREATED"
|
(shape: ResultCode) => "OK" | "CREATED"
|
||||||
>();
|
>();
|
||||||
@@ -66,36 +60,30 @@ type Contact =
|
|||||||
|
|
||||||
const format = getTaggedUnionMatcher<Contact>()("kind")({
|
const format = getTaggedUnionMatcher<Contact>()("kind")({
|
||||||
email: (e) => {
|
email: (e) => {
|
||||||
expectTypeOf(e).not.toBeAny();
|
|
||||||
expectTypeOf(e).toEqualTypeOf<{ kind: "email"; address: string }>();
|
expectTypeOf(e).toEqualTypeOf<{ kind: "email"; address: string }>();
|
||||||
return e.address;
|
return e.address;
|
||||||
},
|
},
|
||||||
phone: (p) => {
|
phone: (p) => {
|
||||||
expectTypeOf(p).not.toBeAny();
|
|
||||||
expectTypeOf(p).toEqualTypeOf<{ kind: "phone"; number: string }>();
|
expectTypeOf(p).toEqualTypeOf<{ kind: "phone"; number: string }>();
|
||||||
return p.number;
|
return p.number;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expectTypeOf(format).not.toBeAny();
|
|
||||||
expectTypeOf(format).toEqualTypeOf<(shape: Contact) => string>();
|
expectTypeOf(format).toEqualTypeOf<(shape: Contact) => string>();
|
||||||
|
|
||||||
const formatW = getTaggedUnionMatcherW<Contact>()("kind")(
|
const formatW = getTaggedUnionMatcherW<Contact>()("kind")(
|
||||||
{
|
{
|
||||||
email: (e) => {
|
email: (e) => {
|
||||||
expectTypeOf(e).not.toBeAny();
|
|
||||||
expectTypeOf(e).toEqualTypeOf<{ kind: "email"; address: string }>();
|
expectTypeOf(e).toEqualTypeOf<{ kind: "email"; address: string }>();
|
||||||
return e.address;
|
return e.address;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
(rest) => {
|
(rest) => {
|
||||||
expectTypeOf(rest).not.toBeAny();
|
|
||||||
expectTypeOf(rest).toEqualTypeOf<{ kind: "phone"; number: string }>();
|
expectTypeOf(rest).toEqualTypeOf<{ kind: "phone"; number: string }>();
|
||||||
return rest.number;
|
return rest.number;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
expectTypeOf(formatW).not.toBeAny();
|
|
||||||
expectTypeOf(formatW).toEqualTypeOf<(shape: Contact) => string>();
|
expectTypeOf(formatW).toEqualTypeOf<(shape: Contact) => string>();
|
||||||
|
|
||||||
export { format, formatW, toStatus, toStatusW };
|
export { format, formatW, toStatus, toStatusW };
|
||||||
+3
-3
@@ -164,9 +164,9 @@ source of truth) and documented in [README § Requirements](../README.md#require
|
|||||||
- **The fixture is a consumer, not a unit test.** `compat/fixture.ts` imports
|
- **The fixture is a consumer, not a unit test.** `compat/fixture.ts` imports
|
||||||
the package by name (`tiny-pattern-ts`), so it resolves through the `exports`
|
the package by name (`tiny-pattern-ts`), so it resolves through the `exports`
|
||||||
map to `dist/index.d.ts` and exercises the emitted declarations' relative
|
map to `dist/index.d.ts` and exercises the emitted declarations' relative
|
||||||
`.ts` specifiers — not the source. `expectTypeOf` / `.not.toBeAny()` are
|
`.ts` specifiers — not the source. `expectTypeOf`'s exact-equality assertions
|
||||||
load-bearing: a bare compile would also pass if a declaration collapsed to
|
are load-bearing: a bare compile would also pass if a declaration collapsed to
|
||||||
`any`; the exact-equality assertions reject that.
|
`any`; they reject that.
|
||||||
|
|
||||||
#### Rejected
|
#### Rejected
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user