Skip to content

Commit 4c40b07

Browse files
authored
Mark internal APIs with @internal JSDoc tag (#104)
## **This PR**: - [X] Marks internal APIs with `@internal` JSDoc tag. - [X] Resolves #103.
1 parent 5ee0181 commit 4c40b07

File tree

4 files changed

+99
-28
lines changed

4 files changed

+99
-28
lines changed

src/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
4545
*
4646
* **_Unexpected failure_**? For a more permissive but less performant
4747
* check that accommodates for equivalent intersection types,
48-
* use {@linkcode branded `.branded.toEqualTypeOf()`}.
49-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
48+
* use {@linkcode branded | .branded.toEqualTypeOf()}.
49+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
5050
*
5151
* @example
5252
* <caption>Using generic type argument syntax</caption>
@@ -86,8 +86,8 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
8686
*
8787
* **_Unexpected failure_**? For a more permissive but less performant
8888
* check that accommodates for equivalent intersection types,
89-
* use {@linkcode branded `.branded.toEqualTypeOf()`}.
90-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
89+
* use {@linkcode branded | .branded.toEqualTypeOf()}.
90+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
9191
*
9292
* @example
9393
* <caption>Using generic type argument syntax</caption>
@@ -119,7 +119,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
119119

120120
toMatchTypeOf: {
121121
/**
122-
* A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`}
122+
* A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
123123
* that allows for extra properties.
124124
* This is roughly equivalent to an `extends` constraint
125125
* in a function type argument.
@@ -146,7 +146,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
146146
): true
147147

148148
/**
149-
* A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`}
149+
* A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
150150
* that allows for extra properties.
151151
* This is roughly equivalent to an `extends` constraint
152152
* in a function type argument.
@@ -205,7 +205,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
205205

206206
/**
207207
* Intersection types can cause issues with
208-
* {@linkcode toEqualTypeOf `.toEqualTypeOf()`}:
208+
* {@linkcode toEqualTypeOf | .toEqualTypeOf()}:
209209
* ```ts
210210
* // ❌ The following line doesn't compile, even though the types are arguably the same.
211211
* expectTypeOf<{ a: 1 } & { b: 2 }>().toEqualTypeOf<{ a: 1; b: 2 }>()
@@ -216,7 +216,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
216216
* __Note__: This comes at a performance cost, and can cause the compiler
217217
* to 'give up' if used with excessively deep types, so use sparingly.
218218
*
219-
* @see {@link https://github.com/mmkal/expect-type/pull/21 Reference}
219+
* @see {@link https://github.com/mmkal/expect-type/pull/21 | Reference}
220220
*/
221221
branded: {
222222
/**
@@ -228,8 +228,8 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
228228
*
229229
* **_Unexpected failure_**? For a more permissive but less performant
230230
* check that accommodates for equivalent intersection types,
231-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
232-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
231+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
232+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
233233
*
234234
* @example
235235
* <caption>Using generic type argument syntax</caption>
@@ -274,8 +274,8 @@ export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
274274
*
275275
* **_Unexpected failure_**? For a more permissive but less performant
276276
* check that accommodates for equivalent intersection types,
277-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
278-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
277+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
278+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
279279
*
280280
* @example
281281
* <caption>Using generic type argument syntax</caption>
@@ -311,8 +311,8 @@ export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
311311
*
312312
* **_Unexpected failure_**? For a more permissive but less performant
313313
* check that accommodates for equivalent intersection types,
314-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
315-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
314+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
315+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
316316
*
317317
* @example
318318
* <caption>Using generic type argument syntax</caption>
@@ -339,7 +339,7 @@ export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
339339
toMatchTypeOf: {
340340
/**
341341
* A less strict version of
342-
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`}
342+
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
343343
* that allows for extra properties.
344344
* This is roughly equivalent to an `extends` constraint
345345
* in a function type argument.
@@ -367,7 +367,7 @@ export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
367367

368368
/**
369369
* A less strict version of
370-
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`}
370+
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
371371
* that allows for extra properties.
372372
* This is roughly equivalent to an `extends` constraint
373373
* in a function type argument.
@@ -502,7 +502,7 @@ export interface BaseExpectTypeOf<Actual, Options extends {positive: boolean}> {
502502
* Checks whether a function is callable with the given parameters.
503503
*
504504
* __Note__: You cannot negate this assertion with
505-
* {@linkcode PositiveExpectTypeOf.not `.not`}, you need to use
505+
* {@linkcode PositiveExpectTypeOf.not | .not}, you need to use
506506
* `ts-expect-error` instead.
507507
*
508508
* @example
@@ -514,7 +514,7 @@ export interface BaseExpectTypeOf<Actual, Options extends {positive: boolean}> {
514514
*
515515
* __Known Limitation__: This assertion will likely fail if you try to use it
516516
* with a generic function or an overload.
517-
* @see {@link https://github.com/mmkal/expect-type/issues/50 This issue} for an example and a workaround.
517+
* @see {@link https://github.com/mmkal/expect-type/issues/50 | This issue} for an example and a workaround.
518518
*
519519
* @param args - The arguments to check for callability.
520520
* @returns `true`.
@@ -855,6 +855,7 @@ export type _ExpectTypeOf = {
855855
* form of a reference or generic type parameter.
856856
*
857857
* @example
858+
* ```ts
858859
* import { foo, bar } from '../foo'
859860
* import { expectTypeOf } from 'expect-type'
860861
*
@@ -867,6 +868,7 @@ export type _ExpectTypeOf = {
867868
* expectTypeOf(bar).parameter(0).toBeString()
868869
* expectTypeOf(bar).returns.not.toBeAny()
869870
* })
871+
* ```
870872
*
871873
* @description
872874
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.

src/messages.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,48 +51,97 @@ export type MismatchInfo<Actual, Expected> =
5151
? Actual
5252
: `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`
5353

54+
/**
55+
* @internal
56+
*/
5457
const inverted = Symbol('inverted')
58+
59+
/**
60+
* @internal
61+
*/
5562
type Inverted<T> = {[inverted]: T}
5663

64+
/**
65+
* @internal
66+
*/
5767
const expectNull = Symbol('expectNull')
5868
export type ExpectNull<T> = {[expectNull]: T; result: ExtendsExcludingAnyOrNever<T, null>}
5969

70+
/**
71+
* @internal
72+
*/
6073
const expectUndefined = Symbol('expectUndefined')
6174
export type ExpectUndefined<T> = {[expectUndefined]: T; result: ExtendsExcludingAnyOrNever<T, undefined>}
6275

76+
/**
77+
* @internal
78+
*/
6379
const expectNumber = Symbol('expectNumber')
6480
export type ExpectNumber<T> = {[expectNumber]: T; result: ExtendsExcludingAnyOrNever<T, number>}
6581

82+
/**
83+
* @internal
84+
*/
6685
const expectString = Symbol('expectString')
6786
export type ExpectString<T> = {[expectString]: T; result: ExtendsExcludingAnyOrNever<T, string>}
6887

88+
/**
89+
* @internal
90+
*/
6991
const expectBoolean = Symbol('expectBoolean')
7092
export type ExpectBoolean<T> = {[expectBoolean]: T; result: ExtendsExcludingAnyOrNever<T, boolean>}
7193

94+
/**
95+
* @internal
96+
*/
7297
const expectVoid = Symbol('expectVoid')
7398
export type ExpectVoid<T> = {[expectVoid]: T; result: ExtendsExcludingAnyOrNever<T, void>}
7499

100+
/**
101+
* @internal
102+
*/
75103
const expectFunction = Symbol('expectFunction')
76104
export type ExpectFunction<T> = {[expectFunction]: T; result: ExtendsExcludingAnyOrNever<T, (...args: any[]) => any>}
77105

106+
/**
107+
* @internal
108+
*/
78109
const expectObject = Symbol('expectObject')
79110
export type ExpectObject<T> = {[expectObject]: T; result: ExtendsExcludingAnyOrNever<T, object>}
80111

112+
/**
113+
* @internal
114+
*/
81115
const expectArray = Symbol('expectArray')
82116
export type ExpectArray<T> = {[expectArray]: T; result: ExtendsExcludingAnyOrNever<T, any[]>}
83117

118+
/**
119+
* @internal
120+
*/
84121
const expectSymbol = Symbol('expectSymbol')
85122
export type ExpectSymbol<T> = {[expectSymbol]: T; result: ExtendsExcludingAnyOrNever<T, symbol>}
86123

124+
/**
125+
* @internal
126+
*/
87127
const expectAny = Symbol('expectAny')
88128
export type ExpectAny<T> = {[expectAny]: T; result: IsAny<T>}
89129

130+
/**
131+
* @internal
132+
*/
90133
const expectUnknown = Symbol('expectUnknown')
91134
export type ExpectUnknown<T> = {[expectUnknown]: T; result: IsUnknown<T>}
92135

136+
/**
137+
* @internal
138+
*/
93139
const expectNever = Symbol('expectNever')
94140
export type ExpectNever<T> = {[expectNever]: T; result: IsNever<T>}
95141

142+
/**
143+
* @internal
144+
*/
96145
const expectNullable = Symbol('expectNullable')
97146
export type ExpectNullable<T> = {[expectNullable]: T; result: Not<StrictEqualUsingBranding<T, NonNullable<T>>>}
98147

src/overloads.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type UnknownFunction = (...args: unknown[]) => unknown
2828
* This is useful because older versions of TypeScript end up with
2929
* 9 "useless" overloads and one real one for parameterless/generic functions.
3030
*
31-
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related}
31+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
3232
*/
3333
export type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<
3434
FunctionType,
@@ -53,7 +53,7 @@ export type Tuplify<Union> = Union extends infer X ? [X] : never
5353
* for parameterless functions. To do this we use
5454
* {@linkcode IsUselessOverloadInfo} to remove useless overloads.
5555
*
56-
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related}
56+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
5757
*/
5858
export type TSPre53OverloadsInfoUnion<FunctionType> =
5959
// 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> = F extends {(...args: infer A1): in
9797
/**
9898
* Get a union of overload variants for a function {@linkcode FunctionType}.
9999
* Does a check for whether we can do the one-shot
100-
* 10-overload matcher (which works for ts>5.3), and if not,
100+
* 10-overload matcher (which works for ts\>5.3), and if not,
101101
* falls back to the more complicated utility.
102102
*/
103103
export type OverloadsInfoUnion<FunctionType> =
@@ -181,7 +181,7 @@ export type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSI
181181
* for parameterless constructors. To do this we use
182182
* {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
183183
*
184-
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 Related}
184+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
185185
*/
186186
export type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> =
187187
// 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<ConstructorType> = Construct
225225
/**
226226
* Get a union of overload variants for a constructor
227227
* {@linkcode ConstructorType}. Does a check for whether we can do the
228-
* one-shot 10-overload matcher (which works for ts>5.3), and if not,
228+
* one-shot 10-overload matcher (which works for ts\>5.3), and if not,
229229
* falls back to the more complicated utility.
230230
*/
231231
export type ConstructorOverloadsUnion<ConstructorType> =
@@ -234,7 +234,9 @@ export type ConstructorOverloadsUnion<ConstructorType> =
234234
? TSPre53ConstructorOverloadsInfoUnion<ConstructorType>
235235
: TSPost53ConstructorOverloadsInfoUnion<ConstructorType>
236236

237-
/** Allows inferring any constructor using the `infer` keyword. */
237+
/**
238+
* Allows inferring any constructor using the `infer` keyword.
239+
*/
238240
// This *looks* fairly pointless but if you try to use `new (...args: any) => any` directly, TypeScript will not infer the constructor type correctly.
239241
export type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType
240242

src/utils.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ export type Eq<Left extends boolean, Right extends boolean> = Left extends true
2828
*/
2929
export type Xor<Types extends [boolean, boolean]> = Not<Eq<Types[0], Types[1]>>
3030

31+
/**
32+
* @internal
33+
*/
3134
const secret = Symbol('secret')
35+
36+
/**
37+
* @internal
38+
*/
3239
type Secret = typeof secret
3340

3441
/**
@@ -103,6 +110,8 @@ export type ReadonlyKeys<T> = Extract<{
103110
// prettier-ignore
104111
/**
105112
* Determines if two types, are equivalent in a `readonly` manner.
113+
*
114+
* @internal
106115
*/
107116
type ReadonlyEquivalent<X, Y> = Extends<
108117
(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)
@@ -123,7 +132,7 @@ export type ExtendsExcludingAnyOrNever<Left, Right> = IsAny<Left> extends true ?
123132
* Checks if two types are strictly equal using
124133
* the TypeScript internal identical-to operator.
125134
*
126-
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 much history}
135+
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
127136
*/
128137
export type StrictEqualUsingTSInternalIdenticalToOperator<L, R> =
129138
(<T>() => T extends (L & T) | T ? true : false) extends <T>() => T extends (R & T) | T ? true : false
@@ -140,14 +149,23 @@ export type StrictEqualUsingTSInternalIdenticalToOperator<L, R> =
140149
*/
141150
export type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>
142151

152+
/**
153+
* @internal
154+
*/
143155
const mismatch = Symbol('mismatch')
156+
157+
/**
158+
* @internal
159+
*/
144160
type Mismatch = {[mismatch]: 'mismatch'}
145161

146162
/**
147163
* A type which should match anything passed as a value but *doesn't*
148164
* match {@linkcode Mismatch}. It helps TypeScript select the right overload
149-
* for {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} and
150-
* {@linkcode PositiveExpectTypeOf.toMatchTypeOf `.toMatchTypeOf()`}.
165+
* for {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} and
166+
* {@linkcode PositiveExpectTypeOf.toMatchTypeOf | .toMatchTypeOf()}.
167+
*
168+
* @internal
151169
*/
152170
const avalue = Symbol('avalue')
153171

@@ -179,7 +197,7 @@ export interface ExpectTypeOfOptions {
179197

180198
/**
181199
* Convert a union to an intersection.
182-
* `A | B | C` -> `A & B & C`
200+
* `A | B | C` -\> `A & B & C`
183201
*/
184202
export type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends (
185203
mergedIntersection: infer Intersection,

0 commit comments

Comments
 (0)