Skip to content

Commit

Permalink
JSDoc improvements (#100)
Browse files Browse the repository at this point in the history
## **This PR**:

- [X] Fixes some typos.
- [X] Renames some type parameters to make their intentions more clear.
- [X] Adds JSDocs to some of the newly added utilities.
  • Loading branch information
aryaemami59 authored Aug 15, 2024
1 parent 67b4188 commit 0bbeffa
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 99 deletions.
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
* @example
* <caption>check that properties exist</caption>
* ```ts
* const obj = {a: 1, b: ''}
* const obj = { a: 1, b: '' }
*
* expectTypeOf(obj).toHaveProperty('a')
*
Expand Down Expand Up @@ -395,7 +395,7 @@ export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
* @example
* <caption>check that properties exist</caption>
* ```ts
* const obj = {a: 1, b: ''}
* const obj = { a: 1, b: '' }
*
* expectTypeOf(obj).toHaveProperty('a')
*
Expand Down Expand Up @@ -519,9 +519,9 @@ export interface BaseExpectTypeOf<Actual, Options extends {positive: boolean}> {
* @returns `true`.
*/
toBeCallableWith: Options['positive'] extends true
? <A extends OverloadParameters<Actual>>(
...args: A
) => ExpectTypeOf<OverloadsNarrowedByParameters<Actual, A>, Options>
? <Args extends OverloadParameters<Actual>>(
...args: Args
) => ExpectTypeOf<OverloadsNarrowedByParameters<Actual, Args>, Options>
: never

/**
Expand All @@ -542,7 +542,7 @@ export interface BaseExpectTypeOf<Actual, Options extends {positive: boolean}> {
* @returns `true`.
*/
toBeConstructibleWith: Options['positive'] extends true
? <A extends ConstructorOverloadParameters<Actual>>(...args: A) => true
? <Args extends ConstructorOverloadParameters<Actual>>(...args: Args) => true
: never

/**
Expand Down Expand Up @@ -854,12 +854,12 @@ export type _ExpectTypeOf = {
* form of a reference or generic type parameter.
*
* @example
* import {foo, bar} from '../foo'
* import {expectTypeOf} from 'expect-type'
* import { foo, bar } from '../foo'
* import { expectTypeOf } from 'expect-type'
*
* test('foo types', () => {
* // make sure `foo` has type {a: number}
* expectTypeOf(foo).toMatchTypeOf({a: 1})
* // make sure `foo` has type { a: number }
* expectTypeOf(foo).toMatchTypeOf({ a: 1 })
* expectTypeOf(foo).toHaveProperty('a').toBeNumber()
*
* // make sure `bar` is a function taking a string:
Expand Down
8 changes: 5 additions & 3 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export type PrintType<T> =

/**
* Helper for showing end-user a hint why their type assertion is failing.
* This swaps "leaf" types with a literal message about what the actual and expected types are.
* Needs to check for Not<IsAny<Actual>> because otherwise LeafTypeOf<Actual> returns never, which extends everything 🤔
* This swaps "leaf" types with a literal message about what the actual and
* expected types are. Needs to check for `Not<IsAny<Actual>>` because
* otherwise `LeafTypeOf<Actual>` returns `never`, which extends everything 🤔
*/
export type MismatchInfo<Actual, Expected> =
And<[Extends<PrintType<Actual>, '...'>, Not<IsAny<Actual>>]> extends true
Expand Down Expand Up @@ -96,7 +97,8 @@ const expectNullable = Symbol('expectNullable')
export type ExpectNullable<T> = {[expectNullable]: T; result: Not<StrictEqualUsingBranding<T, NonNullable<T>>>}

/**
* Checks if the result of an expecter matches the specified options, and resolves to a fairly readable error messsage if not.
* Checks if the result of an expecter matches the specified options, and
* resolves to a fairly readable error message if not.
*/
export type Scolder<
Expecter extends {result: boolean},
Expand Down
Loading

0 comments on commit 0bbeffa

Please sign in to comment.