Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve overloads support, attempt 2 #83

Merged
merged 46 commits into from
Aug 13, 2024
Merged

improve overloads support, attempt 2 #83

merged 46 commits into from
Aug 13, 2024

Conversation

mmkal
Copy link
Owner

@mmkal mmkal commented Jul 26, 2024

Related to #58
Related to #30

Improve support for overloaded functions (up to 10 overloads). So for an example function type:

type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}

.parameters gives you an ExpectTypeOf instance with a union of the parameter-tuple types, so:

expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()

.returns gives you an ExpectTypeOf instance with a union of the return types, so

expectTypeOf<Factorize>().returns.toEqualTypeOf<number[] | bigint[]>()

.toBeCallableWith(...) now accepts any overload input, not just the "last" like before. And you can now chain it via .returns which gives you the matching return type:

expectTypeOf<Factorize>().toBeCallableWith(5).returns.toEqualTypeOf<number[]>()

Implementation

  • overload utilities were added
    • initially, I thought all that was needed was a utility that matches F typeargs against a single 10-overload type
    • but the test-types job caught that this doesn't work for typescript <5.3
    • for lower typescript versions, it seems we need an approach more like the one in Support function overloads #58
    • there are some edge cases the tests found for generic functions and parameterless functions, so there is sometimes some "useless" overload info that has to be explicitly excluded
    • there are a couple of intermediate utilities to check if the 10-overload type can be used, and to exclude "useless" overloads
  • equivalents added for constructor parameters too
  • used the overloaded versions in DeepBrand too
update: moved these changes to #93 to reduce diff
  • I felt the megafile index.ts was finally getting too big with the added overload utilties:
    • so those were put in a new overloads.ts
    • since overload utils they rely on some other existing utils, I created utils.ts to avoid circular references
    • index.ts remains as the home for the main ExpectTypeOf exports
    • added export * from './utils' since we have been exporting all the internal utils and I don't want to break people
    • update: moved these changes to create utils file #93 to reduce diff

@mmkal mmkal marked this pull request as draft July 26, 2024 18:15
@aryaemami59
Copy link
Collaborator

Sorry I took too long with #58. Does this supersede that one?

@mmkal
Copy link
Owner Author

mmkal commented Jul 26, 2024

Yes, I wrote this using that as a reference, I'd like it to be a replacement yeah. Need to go through carefully and make sure nothing is dropped between the two though.

@aryaemami59
Copy link
Collaborator

Gotcha, I will look through it soon.

also use individual `// prettier-ignore`s to avoid non-eslint prettier tooling from "fixing" the formatting
typescript can handle the circular ref but it just feels bad to have one. index.ts was getting big anyway
@mmkal mmkal changed the title better overloads support improve overloads support, attempt 2 Aug 1, 2024
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
test/usage.test.ts Outdated Show resolved Hide resolved
@mmkal
Copy link
Owner Author

mmkal commented Aug 1, 2024

@aryaemami59 I've updated the description of this pull request to explain what's going on in it better, both in terms of the API surface change, and the implementation. Worth having a look at if you're planning on diving into the code.

Would be great to get your thoughts on whether you think this is a good idea, or whether it's too much complexity.

I think it's quite possible there are more edge cases around generics etc., and it could get out of hand if there's more edge case handling needed. On the other hand, kind of the point of this library is to abstract that kind of complexity away from regular typescript users who just want to test their types in a sensible way, so maybe the more complex it is, the more value this library is bringing - even if it does become harder to maintain.

CC @trevorade @sheremet-va @y-polonsk in case you want to weigh in too.

@aryaemami59 aryaemami59 added the New feature New feature or request label Aug 1, 2024
@aryaemami59
Copy link
Collaborator

@mmkal, I'm going to take a deep dive today and will let you know my full thoughts on it.

Here are my initial thoughts:

  • I really like that you can now chain toBeCallableWith() with .returns. I think this is something we should explore and possibly use more often.
  • If .parameters now requires a union of parameter-tuple types and .returns requires a union of return types, does this mean it will cause a breaking change? If so, do you think this is something we should add as an opt-in feature?

@mmkal
Copy link
Owner Author

mmkal commented Aug 1, 2024

Yes, it could be considered a breaking change since assertions that are currently passing would start failing. But I don't think it should be configurable because:

  1. It would add maintenance and API surface complexity and not really add any value other than backcompat
  2. People who want the old behaviour for some reason can still get it using the built in Parameters<...> etc.
  3. Arguably the assertions that start newly failing are already probably hiding a missing bug so in a way it's the opposite of a breaking change (given this is a testing library)
  4. The library is still v0

package.json Outdated Show resolved Hide resolved
- Corrected whitespace problems in `utils.ts` that were causing JSDoc comments to be misaligned in the final build output.
@mmkal mmkal mentioned this pull request Aug 9, 2024
@mmkal
Copy link
Owner Author

mmkal commented Aug 9, 2024

Updates since last time:

  • convert overloads to a union of functions rather than a tuple
  • various simplifications that fall out of that
  • constructor parameters support in a similar way
  • some non-readme tests in types.test.ts

Next:

  • use the overload helpers in DeepBrand - currently it won't distinguish between overloaded functions and we should be consistent

src/overloads.ts Outdated Show resolved Hide resolved
src/overloads.ts Outdated Show resolved Hide resolved
src/overloads.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
src/overloads.ts Show resolved Hide resolved
src/overloads.ts Outdated Show resolved Hide resolved
mmkal added a commit that referenced this pull request Aug 11, 2024
Another intermediate PR in support of #83

Moves `DeepBrand` to its own file, because in #83 I want to start using
imports from `overloads.ts` in it. This would be a circular reference,
which TypeScript can actually handle, but I would still like to avoid to
prevent confusion.

Similarly I had to create _another_ file `messages.ts` since we have a
few type-error aiding utilities that are currently in utils.ts, but that
rely on `DeepBrand`.

This tends to be the kind of file-proliferation that I worry about when
breaking up a mega-file! But in this case I think it's warranted.

@aryaemami59 what do you think re naming/ the new structure?

---------

Co-authored-by: Misha Kaletsky <[email protected]>
@mmkal mmkal marked this pull request as ready for review August 11, 2024 18:48
@mmkal mmkal mentioned this pull request Aug 12, 2024
@mmkal mmkal requested a review from aryaemami59 August 12, 2024 13:01
@aryaemami59
Copy link
Collaborator

Alright let's get this in.

@aryaemami59 aryaemami59 merged commit 7c63c23 into main Aug 13, 2024
23 checks passed
@aryaemami59 aryaemami59 deleted the overloadsagain branch August 13, 2024 05:08
@aryaemami59 aryaemami59 linked an issue Aug 13, 2024 that may be closed by this pull request
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 20, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 20, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
kodiakhq bot referenced this pull request in X-oss-byte/Nextjs Aug 20, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [expect-type](https://togithub.com/mmkal/expect-type) | [`0.19.0` -> `0.20.0`](https://renovatebot.com/diffs/npm/expect-type/0.19.0/0.20.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/expect-type/0.20.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/expect-type/0.20.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/expect-type/0.19.0/0.20.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/expect-type/0.19.0/0.20.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>mmkal/expect-type (expect-type)</summary>

### [`v0.20.0`](https://togithub.com/mmkal/expect-type/releases/tag/v0.20.0)

[Compare Source](https://togithub.com/mmkal/expect-type/compare/0.19.0...v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@&#8203;mmkal](https://togithub.com/mmkal) in [https://github.com/mmkal/expect-type/pull/83](https://togithub.com/mmkal/expect-type/pull/83)

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#&#8203;83](https://togithub.com/mmkal/expect-type/issues/83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://togithub.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@&#8203;mrazauskas](https://togithub.com/mrazauskas) in [https://github.com/mmkal/expect-type/pull/69](https://togithub.com/mmkal/expect-type/pull/69)
-   Fix minor issues in docs by [@&#8203;aryaemami59](https://togithub.com/aryaemami59) in [https://github.com/mmkal/expect-type/pull/91](https://togithub.com/mmkal/expect-type/pull/91)
-   create utils file by [@&#8203;mmkal](https://togithub.com/mmkal) in [https://github.com/mmkal/expect-type/pull/93](https://togithub.com/mmkal/expect-type/pull/93)
-   branding.ts and messages.ts by [@&#8203;mmkal](https://togithub.com/mmkal) in [https://github.com/mmkal/expect-type/pull/95](https://togithub.com/mmkal/expect-type/pull/95)
-   improve overloads support, attempt 2 by [@&#8203;mmkal](https://togithub.com/mmkal) in [https://github.com/mmkal/expect-type/pull/83](https://togithub.com/mmkal/expect-type/pull/83)
-   Extends: explain myself  [`1e37116`](https://togithub.com/mmkal/expect-type/commit/1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#&#8203;104](https://togithub.com/mmkal/expect-type/issues/104))  [`4c40b07`](https://togithub.com/mmkal/expect-type/commit/4c40b07)
-   Re-export everything in `overloads.ts` file ([#&#8203;107](https://togithub.com/mmkal/expect-type/issues/107))  [`5ee0181`](https://togithub.com/mmkal/expect-type/commit/5ee0181)
-   JSDoc improvements ([#&#8203;100](https://togithub.com/mmkal/expect-type/issues/100))  [`0bbeffa`](https://togithub.com/mmkal/expect-type/commit/0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/X-oss-byte/Nextjs).
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 21, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
renovate bot added a commit to mmkal/trpc-cli that referenced this pull request Aug 22, 2024
##### [`v0.20.0](https://github.com/mmkal/expect-type/releases/tag/v0.20.0)

#### Breaking changes

-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83

This change updates how overloaded functions are treated. Now, `.parameters` gives you a *union* of the parameter-tuples that a function can take. For example, given the following type:

```ts
type Factorize = {
  (input: number): number[]
  (input: bigint): bigint[]
}
```

Behvaiour before:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[bigint]>()
```

Behaviour now:

```ts
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
```

There were similar changes for `.returns`, `.parameter(...)`, and `.toBeCallableWith`. Also, overloaded functions are now differentiated properly when using `.branded.toEqualTypeOf` (this was a bug that it seems nobody found).

See [#83](mmkal/expect-type#83) for more details or look at the updated docs (including a new section called "[Overloaded functions](https://github.com/mmkal/expect-type#overloaded-functions)", which has more info on how this behaviour differs for TypeScript versions before 5.3).

#### What's Changed

-   Fix rendering issue in readme by [@mrazauskas](https://github.com/mrazauskas) in mmkal/expect-type#69
-   Fix minor issues in docs by [@aryaemami59](https://github.com/aryaemami59) in mmkal/expect-type#91
-   create utils file by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#93
-   branding.ts and messages.ts by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#95
-   improve overloads support, attempt 2 by [@mmkal](https://github.com/mmkal) in mmkal/expect-type#83
-   Extends: explain myself  [`1e37116`](mmkal/expect-type@1e37116)
-   Mark internal APIs with `@internal` JSDoc tag ([#104](mmkal/expect-type#104))  [`4c40b07`](mmkal/expect-type@4c40b07)
-   Re-export everything in `overloads.ts` file ([#107](mmkal/expect-type#107))  [`5ee0181`](mmkal/expect-type@5ee0181)
-   JSDoc improvements ([#100](mmkal/expect-type#100))  [`0bbeffa`](mmkal/expect-type@0bbeffa)

**Full Changelog**: mmkal/expect-type@v0.19.0...v0.20.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Contains breaking changes New feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support overloaded functions
3 participants