diff --git a/src/index.ts b/src/index.ts index 008ae61..a9c1d7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,8 +45,8 @@ export interface PositiveExpectTypeOf extends BaseExpectTypeOfUsing generic type argument syntax @@ -86,8 +86,8 @@ export interface PositiveExpectTypeOf extends BaseExpectTypeOfUsing generic type argument syntax @@ -119,7 +119,7 @@ export interface PositiveExpectTypeOf extends BaseExpectTypeOf extends BaseExpectTypeOf extends BaseExpectTypeOf().toEqualTypeOf<{ a: 1; b: 2 }>() @@ -216,7 +216,7 @@ export interface PositiveExpectTypeOf extends BaseExpectTypeOf extends BaseExpectTypeOfUsing generic type argument syntax @@ -274,8 +274,8 @@ export interface NegativeExpectTypeOf extends BaseExpectTypeOfUsing generic type argument syntax @@ -311,8 +311,8 @@ export interface NegativeExpectTypeOf extends BaseExpectTypeOfUsing generic type argument syntax @@ -339,7 +339,7 @@ export interface NegativeExpectTypeOf extends BaseExpectTypeOf extends BaseExpectTypeOf { * Checks whether a function is callable with the given parameters. * * __Note__: You cannot negate this assertion with - * {@linkcode PositiveExpectTypeOf.not `.not`}, you need to use + * {@linkcode PositiveExpectTypeOf.not | .not}, you need to use * `ts-expect-error` instead. * * @example @@ -514,7 +514,7 @@ export interface BaseExpectTypeOf { * * __Known Limitation__: This assertion will likely fail if you try to use it * with a generic function or an overload. - * @see {@link https://github.com/mmkal/expect-type/issues/50 This issue} for an example and a workaround. + * @see {@link https://github.com/mmkal/expect-type/issues/50 | This issue} for an example and a workaround. * * @param args - The arguments to check for callability. * @returns `true`. @@ -855,6 +855,7 @@ export type _ExpectTypeOf = { * form of a reference or generic type parameter. * * @example + * ```ts * import { foo, bar } from '../foo' * import { expectTypeOf } from 'expect-type' * @@ -867,6 +868,7 @@ export type _ExpectTypeOf = { * expectTypeOf(bar).parameter(0).toBeString() * expectTypeOf(bar).returns.not.toBeAny() * }) + * ``` * * @description * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. diff --git a/src/messages.ts b/src/messages.ts index 05b2a7b..81d2de1 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -51,48 +51,97 @@ export type MismatchInfo = ? Actual : `Expected: ${PrintType}, Actual: ${PrintType>}` +/** + * @internal + */ const inverted = Symbol('inverted') + +/** + * @internal + */ type Inverted = {[inverted]: T} +/** + * @internal + */ const expectNull = Symbol('expectNull') export type ExpectNull = {[expectNull]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectUndefined = Symbol('expectUndefined') export type ExpectUndefined = {[expectUndefined]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectNumber = Symbol('expectNumber') export type ExpectNumber = {[expectNumber]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectString = Symbol('expectString') export type ExpectString = {[expectString]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectBoolean = Symbol('expectBoolean') export type ExpectBoolean = {[expectBoolean]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectVoid = Symbol('expectVoid') export type ExpectVoid = {[expectVoid]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectFunction = Symbol('expectFunction') export type ExpectFunction = {[expectFunction]: T; result: ExtendsExcludingAnyOrNever any>} +/** + * @internal + */ const expectObject = Symbol('expectObject') export type ExpectObject = {[expectObject]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectArray = Symbol('expectArray') export type ExpectArray = {[expectArray]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectSymbol = Symbol('expectSymbol') export type ExpectSymbol = {[expectSymbol]: T; result: ExtendsExcludingAnyOrNever} +/** + * @internal + */ const expectAny = Symbol('expectAny') export type ExpectAny = {[expectAny]: T; result: IsAny} +/** + * @internal + */ const expectUnknown = Symbol('expectUnknown') export type ExpectUnknown = {[expectUnknown]: T; result: IsUnknown} +/** + * @internal + */ const expectNever = Symbol('expectNever') export type ExpectNever = {[expectNever]: T; result: IsNever} +/** + * @internal + */ const expectNullable = Symbol('expectNullable') export type ExpectNullable = {[expectNullable]: T; result: Not>>} diff --git a/src/overloads.ts b/src/overloads.ts index 5254d86..45088ce 100644 --- a/src/overloads.ts +++ b/src/overloads.ts @@ -28,7 +28,7 @@ export type UnknownFunction = (...args: unknown[]) => unknown * This is useful because older versions of TypeScript end up with * 9 "useless" overloads and one real one for parameterless/generic functions. * - * @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related} + * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related} */ export type IsUselessOverloadInfo = StrictEqualUsingTSInternalIdenticalToOperator< FunctionType, @@ -53,7 +53,7 @@ export type Tuplify = Union extends infer X ? [X] : never * for parameterless functions. To do this we use * {@linkcode IsUselessOverloadInfo} to remove useless overloads. * - * @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related} + * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related} */ export type TSPre53OverloadsInfoUnion = // first, pointlessly wrap the overload variants in a 1-tuple, then infer them as `Tup` - this helps TypeScript isolate out the overload variants @@ -97,7 +97,7 @@ export type DecreasingOverloadsInfoUnion = F extends {(...args: infer A1): in /** * Get a union of overload variants for a function {@linkcode FunctionType}. * Does a check for whether we can do the one-shot - * 10-overload matcher (which works for ts>5.3), and if not, + * 10-overload matcher (which works for ts\>5.3), and if not, * falls back to the more complicated utility. */ export type OverloadsInfoUnion = @@ -181,7 +181,7 @@ export type IsUselessConstructorOverloadInfo = StrictEqualUsingTSI * for parameterless constructors. To do this we use * {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads. * - * @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related} + * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related} */ export type TSPre53ConstructorOverloadsInfoUnion = // first, pointlessly wrap the overload variants in a 1-tuple, then infer them as `Tup` - this helps TypeScript isolate out the overload variants @@ -225,7 +225,7 @@ export type DecreasingConstructorOverloadsInfoUnion = Construct /** * Get a union of overload variants for a constructor * {@linkcode ConstructorType}. Does a check for whether we can do the - * one-shot 10-overload matcher (which works for ts>5.3), and if not, + * one-shot 10-overload matcher (which works for ts\>5.3), and if not, * falls back to the more complicated utility. */ export type ConstructorOverloadsUnion = @@ -234,7 +234,9 @@ export type ConstructorOverloadsUnion = ? TSPre53ConstructorOverloadsInfoUnion : TSPost53ConstructorOverloadsInfoUnion -/** Allows inferring any constructor using the `infer` keyword. */ +/** + * Allows inferring any constructor using the `infer` keyword. + */ // This *looks* fairly pointless but if you try to use `new (...args: any) => any` directly, TypeScript will not infer the constructor type correctly. export type InferConstructor any> = ConstructorType diff --git a/src/utils.ts b/src/utils.ts index 0b25cb6..be5054f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -28,7 +28,14 @@ export type Eq = Left extends true */ export type Xor = Not> +/** + * @internal + */ const secret = Symbol('secret') + +/** + * @internal + */ type Secret = typeof secret /** @@ -103,6 +110,8 @@ export type ReadonlyKeys = Extract<{ // prettier-ignore /** * Determines if two types, are equivalent in a `readonly` manner. + * + * @internal */ type ReadonlyEquivalent = Extends< (() => T extends X ? true : false), (() => T extends Y ? true : false) @@ -123,7 +132,7 @@ export type ExtendsExcludingAnyOrNever = IsAny extends true ? * Checks if two types are strictly equal using * the TypeScript internal identical-to operator. * - * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 much history} + * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history} */ export type StrictEqualUsingTSInternalIdenticalToOperator = (() => T extends (L & T) | T ? true : false) extends () => T extends (R & T) | T ? true : false @@ -140,14 +149,23 @@ export type StrictEqualUsingTSInternalIdenticalToOperator = */ export type MutuallyExtends = And<[Extends, Extends]> +/** + * @internal + */ const mismatch = Symbol('mismatch') + +/** + * @internal + */ type Mismatch = {[mismatch]: 'mismatch'} /** * A type which should match anything passed as a value but *doesn't* * match {@linkcode Mismatch}. It helps TypeScript select the right overload - * for {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} and - * {@linkcode PositiveExpectTypeOf.toMatchTypeOf `.toMatchTypeOf()`}. + * for {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} and + * {@linkcode PositiveExpectTypeOf.toMatchTypeOf | .toMatchTypeOf()}. + * + * @internal */ const avalue = Symbol('avalue') @@ -179,7 +197,7 @@ export interface ExpectTypeOfOptions { /** * Convert a union to an intersection. - * `A | B | C` -> `A & B & C` + * `A | B | C` -\> `A & B & C` */ export type UnionToIntersection = (Union extends any ? (distributedUnion: Union) => void : never) extends ( mergedIntersection: infer Intersection,