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

chore(deps): update dependency ts-pattern to v5.6.0 #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented May 23, 2024

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
ts-pattern 5.0.8 -> 5.6.0 age adoption passing confidence

Release Notes

gvergnaud/ts-pattern (ts-pattern)

v5.6.0

Compare Source

This release contains two changes:

Typecheck pattern when using isMatching with 2 parameter.

It used to be possible to pass a pattern than could never match to isMatching. The new version checks that the provide pattern does match the value in second parameter:

type Pizza = { type: 'pizza'; topping: string };
type Sandwich = { type: 'sandwich'; condiments: string[] };
type Food = Pizza | Sandwich;

const fn = (food: Pizza | Sandwich) => {
    if (isMatching({ type: 'oops' }, food)) {
        //                  👆 used to type-check, now doesn't!
    }
}
Do not use P.infer as an inference point

When using P.infer<Pattern> to type a function argument, like in the following example:

const getWithDefault = <T extends P.Pattern>(
  input: unknown,
  pattern: T,
  defaultValue: P.infer<T> //  👈
): P.infer<T> =>
  isMatching(pattern, input) ? input : defaultValue

TypeScript could get confused and find type errors in the wrong spot:

const res = getWithDefault(null, { x: P.string }, 'oops') 
//                                     👆           👆 type error should be here
//                                 but it's here 😬

This new version fixes this problem.

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.5.0...v5.6.0

v5.5.0

Compare Source

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.4.0...v5.5.0

v5.4.0

Compare Source

The main thing — Faster type checking 🚀

This release brings a significant perf improvement to exhaustiveness checking, which led to a ~16% decrease in the time to type-check the full test suite of TS-Pattern:

Category Before After Evolution (%)
Instantiations 6,735,991 4,562,378 -32.33%
Memory used 732,233K 746,454K 1.95%
Assignability cache size 209,959 205,926 -1.92%
Identity cache size 28,093 28,250 0.56%
Check time 5.78s 4.83s -16.44%

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.3.1...v5.4.0

v5.3.1

Compare Source

Pattern-matching on symbol keys

Symbols used to be ignored in object patterns. They are now taken into account:

const symbolA = Symbol('symbol-a');
const symbolB = Symbol('symbol-b');

const obj = { [symbolA]: { [symbolB]: 'foo' } };
    
if (isMatching({ [symbolA]: { [symbolB]: 'bar' } }, obj)) {
   //  👆 Used to return true, now returns false!
   
   //  Since TS-Pattern wasn't reading symbols, this pattern used to be equivalent
   //  to the `{}` pattern that matches any value except null and undefined.
}

.exhaustive now throws a custom error

People have expressed the need to differentiate runtime errors that .exhaustive() might throw when the input is of an unexpected type from other runtime errors that could have happened in the same match expression. It's now possible with err instanceof NonExhaustiveError:

import { match, P, NonExhaustiveError }  from 'ts-pattern';

const fn = (input: string | number) => {
  return match(input)
    .with(P.string, () => "string!")
    .with(P.number, () => "number!")
    .exhaustive()
}

try {
  fn(null as string) // 👈 💥 
} catch (e) {
  if (e instanceof NonExhaustiveError) {
    // The input was invalid
  } else {
    // something else happened
  }
}

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.2.0...v5.3.1

v5.3.0

Compare Source

v5.2.0

Compare Source

The main thing

new P.string.length(n) pattern

P.string.length(len) matches strings with exactly len characters.

const fn = (input: string) =>
  match(input)
    .with(P.string.length(2), () => '🎉')
    .otherwise(() => '❌');

console.log(fn('ok')); // logs '🎉'

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.1.2...v5.2.0

v5.1.2

Compare Source

The main thing

When combining P.nonNullable and P.nullish, you should get an exhaustive pattern matching expression, but the following case was incorrectly considered non-exhaustive:

declare const input: {
  nested: string | number | null | undefined;
};

const res = match(input)
  .with({ nested: P.nonNullable }, (x) => {/* ... */})
  .with({ nested: P.nullish }, (x) => {/* ... */})
  // should type-check
  .exhaustive();

This is fixed now.

What's Changed
New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.1.1...v5.1.2

v5.1.1

Compare Source

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.1.0...v5.1.1

v5.1.0

Compare Source

New features
P.nonNullable wildcard

Add a new P.nonNullable pattern that will match any value except null or undefined.

import { match, P } from 'ts-pattern';

const input = null;

const output = match<number | null | undefined>(input)
  .with(P.nonNullable, () => 'it is a number!')
  .otherwise(() => 'it is either null or undefined!');

console.log(output);
// => 'it is either null or undefined!'

Closes #​60 #​154 #​190 and will be a work-around for #​143.

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.0.8...v5.1.0


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. View the repository job log.

Copy link

changeset-bot bot commented May 23, 2024

⚠️ No Changeset found

Latest commit: 8bafe2c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 902b856 to 66ea1e1 Compare May 24, 2024 08:41
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.1.1 chore(deps): update dependency ts-pattern to v5.1.2 May 24, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 66ea1e1 to 5da84cc Compare June 15, 2024 02:36
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.1.2 chore(deps): update dependency ts-pattern to v5.2.0 Jun 15, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 5da84cc to 218b535 Compare August 12, 2024 05:32
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.2.0 chore(deps): update dependency ts-pattern to v5.3.1 Aug 12, 2024
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.3.1 chore(deps): update dependency ts-pattern to v5.4.0 Sep 26, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 218b535 to d42c3a2 Compare September 26, 2024 08:38
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from d42c3a2 to ac5b231 Compare October 16, 2024 05:56
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.4.0 chore(deps): update dependency ts-pattern to v5.5.0 Oct 16, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from ac5b231 to 8bafe2c Compare December 16, 2024 01:47
@renovate renovate bot changed the title chore(deps): update dependency ts-pattern to v5.5.0 chore(deps): update dependency ts-pattern to v5.6.0 Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants