astronomy-club-at-nitic / nitic-astronomy

The website of Astronomy Club at NITIC.
https://nitic-astronomy-website.vercel.app
MIT License
2 stars 0 forks source link

fix(deps): update dependency ts-pattern to v5 #191

Open renovate[bot] opened 1 year ago

renovate[bot] commented 1 year ago

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
ts-pattern 4.3.0 -> 5.3.1 age adoption passing confidence

Release Notes

gvergnaud/ts-pattern (ts-pattern) ### [`v5.3.1`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.3.1) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/b2e7566e1906068cba911825f27d76e6d53fc6c2...v5.3.1) #### Pattern-matching on symbol keys Symbols used to be ignored in object patterns. They are now taken into account: ```ts 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`: ```ts 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 - build(deps-dev): bump braces from 3.0.2 to 3.0.3 in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/262](https://togithub.com/gvergnaud/ts-pattern/pull/262) - feat: throw custom `ExhaustiveError` when no matched pattern by [@​adamhamlin](https://togithub.com/adamhamlin) in [https://github.com/gvergnaud/ts-pattern/pull/270](https://togithub.com/gvergnaud/ts-pattern/pull/270) - Symbols as keys by [@​Ayc0](https://togithub.com/Ayc0) in [https://github.com/gvergnaud/ts-pattern/pull/272](https://togithub.com/gvergnaud/ts-pattern/pull/272) #### New Contributors - [@​adamhamlin](https://togithub.com/adamhamlin) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/270](https://togithub.com/gvergnaud/ts-pattern/pull/270) - [@​Ayc0](https://togithub.com/Ayc0) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/272](https://togithub.com/gvergnaud/ts-pattern/pull/272) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.2.0...v5.3.1 ### [`v5.3.0`](https://togithub.com/gvergnaud/ts-pattern/compare/v5.2.0...b2e7566e1906068cba911825f27d76e6d53fc6c2) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.2.0...b2e7566e1906068cba911825f27d76e6d53fc6c2) ### [`v5.2.0`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.2.0) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.1.2...v5.2.0) #### The main thing ##### new `P.string.length(n)` pattern `P.string.length(len)` matches strings with exactly `len` characters. ```ts const fn = (input: string) => match(input) .with(P.string.length(2), () => '🎉') .otherwise(() => '❌'); console.log(fn('ok')); // logs '🎉' ``` #### What's Changed - docs: fix typo in `P.when` patterns code example by [@​grigorischristainas](https://togithub.com/grigorischristainas) in [https://github.com/gvergnaud/ts-pattern/pull/260](https://togithub.com/gvergnaud/ts-pattern/pull/260) - feat: Added P.string.length by [@​JUSTIVE](https://togithub.com/JUSTIVE) in [https://github.com/gvergnaud/ts-pattern/pull/257](https://togithub.com/gvergnaud/ts-pattern/pull/257) #### New Contributors - [@​grigorischristainas](https://togithub.com/grigorischristainas) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/260](https://togithub.com/gvergnaud/ts-pattern/pull/260) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.1.2...v5.2.0 ### [`v5.1.2`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.1.2) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.1.1...v5.1.2) ##### 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: ```ts 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 - build(deps): bump postcss and react-scripts in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/243](https://togithub.com/gvergnaud/ts-pattern/pull/243) - build(deps): bump loader-utils and react-scripts in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/242](https://togithub.com/gvergnaud/ts-pattern/pull/242) - build(deps): bump jsdom and react-scripts in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/241](https://togithub.com/gvergnaud/ts-pattern/pull/241) - build(deps): bump tough-cookie and react-scripts in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/240](https://togithub.com/gvergnaud/ts-pattern/pull/240) - build(deps): bump shell-quote and react-scripts in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/239](https://togithub.com/gvergnaud/ts-pattern/pull/239) - chore: add P.map specific jsdoc for P.map by [@​momentiris](https://togithub.com/momentiris) in [https://github.com/gvergnaud/ts-pattern/pull/245](https://togithub.com/gvergnaud/ts-pattern/pull/245) - build(deps-dev): bump ejs from 3.1.9 to 3.1.10 in /examples/gif-fetcher by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/249](https://togithub.com/gvergnaud/ts-pattern/pull/249) - build(deps-dev): bump ejs from 3.1.9 to 3.1.10 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/248](https://togithub.com/gvergnaud/ts-pattern/pull/248) - fix: exhaustive checking with nested P.nonNullable patterns by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/252](https://togithub.com/gvergnaud/ts-pattern/pull/252) ##### New Contributors - [@​momentiris](https://togithub.com/momentiris) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/245](https://togithub.com/gvergnaud/ts-pattern/pull/245) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.1.1...v5.1.2 ### [`v5.1.1`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.1.1) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.1.0...v5.1.1) #### What's Changed - Fix(P.nonNullable): narrowing of unions of objects by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/237](https://togithub.com/gvergnaud/ts-pattern/pull/237) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.1.0...v5.1.1 ### [`v5.1.0`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.1.0) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.8...v5.1.0) ##### New features ##### `P.nonNullable` wildcard Add a new `P.nonNullable` pattern that will match any value except `null` or `undefined`. ```ts import { match, P } from 'ts-pattern'; const input = null; const output = match(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](https://togithub.com/gvergnaud/ts-pattern/issues/60) [#​154](https://togithub.com/gvergnaud/ts-pattern/issues/154) [#​190](https://togithub.com/gvergnaud/ts-pattern/issues/190) and will be a work-around for [#​143](https://togithub.com/gvergnaud/ts-pattern/issues/143). ##### What's Changed - feat: Add P.nonNullable patterns by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/229](https://togithub.com/gvergnaud/ts-pattern/pull/229) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.8...v5.1.0 ### [`v5.0.8`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.8) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/d0d07c9617f8bb9699c97c05c8c74eb542f081f2...v5.0.8) #### The main thing This release includes type narrowing improvement to `isMatching` when used in its curried form: ```ts type Pizza = { type: 'pizza', topping: string }; type Sandwich = { type: 'sandwich', condiments: string[] } type Food = Pizza | Sandwich; declare const food: Food const isPizza = isMatching({ type: 'pizza' }) if (isPizza(food)) { x // Used to infer `food` as `Food`, no infers `Pizza` } ``` This also improves type checking performance for complex patterns and fixes a small bug in the ES5 build of TS-Pattern. #### What's Changed - perf: support exhaustive match on larger unions by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/214](https://togithub.com/gvergnaud/ts-pattern/pull/214) - fix: make isMatching(p) infer the pattern as a const type parameter by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/221](https://togithub.com/gvergnaud/ts-pattern/pull/221) - fix: Make sure regeneratorRuntime isn't included in the cjs build by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/224](https://togithub.com/gvergnaud/ts-pattern/pull/224) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.6...v5.0.8 ### [`v5.0.7`](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.6...d0d07c9617f8bb9699c97c05c8c74eb542f081f2) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.6...d0d07c9617f8bb9699c97c05c8c74eb542f081f2) ### [`v5.0.6`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.6) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.5...v5.0.6) #### Close issue issues - Exhaustive matching fix for read only arrays [https://github.com/gvergnaud/ts-pattern/issues/206](https://togithub.com/gvergnaud/ts-pattern/issues/206) - Fix incorrect JS docs [https://github.com/gvergnaud/ts-pattern/issues/196](https://togithub.com/gvergnaud/ts-pattern/issues/196) #### What's Changed - Update README.md by [@​ndstephens](https://togithub.com/ndstephens) in [https://github.com/gvergnaud/ts-pattern/pull/161](https://togithub.com/gvergnaud/ts-pattern/pull/161) - docs: add install instructions for bun and pnpm by [@​colinhacks](https://togithub.com/colinhacks) in [https://github.com/gvergnaud/ts-pattern/pull/186](https://togithub.com/gvergnaud/ts-pattern/pull/186) - build(deps-dev): bump postcss from 8.4.23 to 8.4.31 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/199](https://togithub.com/gvergnaud/ts-pattern/pull/199) - build(deps-dev): bump [@​babel/traverse](https://togithub.com/babel/traverse) from 7.21.5 to 7.23.2 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gvergnaud/ts-pattern/pull/200](https://togithub.com/gvergnaud/ts-pattern/pull/200) - fix(readonly): exhaustive matching on readonly array by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/207](https://togithub.com/gvergnaud/ts-pattern/pull/207) #### New Contributors - [@​ndstephens](https://togithub.com/ndstephens) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/161](https://togithub.com/gvergnaud/ts-pattern/pull/161) - [@​colinhacks](https://togithub.com/colinhacks) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/186](https://togithub.com/gvergnaud/ts-pattern/pull/186) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.5...v5.0.6 ### [`v5.0.5`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.5) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.4...v5.0.5) #### Bug fixes The `P` module was mistakenly exposing some pattern methods that were intended to be namespaced by type. This release fixes this problem. If you happened to use on of those following methods, here is where to find them now: ```diff - P.between + P.number.between ``` ```diff - P.lt + P.number.lt ``` ```diff - P.gt + P.number.gt ``` ```diff - P.lte + P.number.lte ``` ```diff - P.gte + P.number.gte ``` ```diff - P.int + P.number.int ``` ```diff - P.finite + P.number.finite ``` ```diff - P.positive + P.number.positive ``` ```diff - P.negative + P.number.negative ``` ```diff - P.betweenBigInt + P.bigint.between ``` ```diff - P.ltBigInt + P.bigint.lt ``` ```diff - P.gtBigInt + P.bigint.gt ``` ```diff - P.lteBigInt + P.bigint.lte ``` ```diff - P.gteBigInt + P.bigint.gte ``` ```diff - P.positiveBigInt + P.bigint.positive ``` ```diff - P.negativeBigInt + P.bigint.negative ``` ### [`v5.0.4`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.4) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.3...v5.0.4) #### What's Changed - 🐛 fix: Accept branded primitive types as patterns by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/180](https://togithub.com/gvergnaud/ts-pattern/pull/180) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.3...v5.0.4 ### [`v5.0.3`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.3) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.2...v5.0.3) #### What's Changed - 🐛 fix: Allow re-exporting patterns from ES Modules by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/175](https://togithub.com/gvergnaud/ts-pattern/pull/175) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.2...v5.0.3 ### [`v5.0.2`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.2) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/7ccc1d3333e424391f0b8e0f1ec0055025448bda...v5.0.2) #### What's Changed - fix(P.infer): Fix inference of arrays containing tuples in https://github.com/gvergnaud/ts-pattern/commit/c52af6a2fa75ac37d8b8e1a1b9832445e4c4f580 - refactoring: simplify selection types in https://github.com/gvergnaud/ts-pattern/commit/1b7a36bb9e6f982f508989d04adec7ccd419cd89 - perf: runtime perf improvement in .with in https://github.com/gvergnaud/ts-pattern/commit/9b2738497974cfe96874853d44d579a41fa8e885 - fix: use `Symbol.for` to make sure two concurrent versions of ts-pattern are compatible with one-another in https://github.com/gvergnaud/ts-pattern/commit/d6d2e23ca98dbbba02b2ee4778c784cc67b858bd - docs: fix typo by [@​juicyjusung](https://togithub.com/juicyjusung) in [https://github.com/gvergnaud/ts-pattern/pull/170](https://togithub.com/gvergnaud/ts-pattern/pull/170) #### New Contributors - [@​juicyjusung](https://togithub.com/juicyjusung) made their first contribution in [https://github.com/gvergnaud/ts-pattern/pull/170](https://togithub.com/gvergnaud/ts-pattern/pull/170) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v5.0.0...v5.0.2 ### [`v5.0.1`](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.0...7ccc1d3333e424391f0b8e0f1ec0055025448bda) [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v5.0.0...7ccc1d3333e424391f0b8e0f1ec0055025448bda) ### [`v5.0.0`](https://togithub.com/gvergnaud/ts-pattern/releases/tag/v5.0.0): ❤️ [Compare Source](https://togithub.com/gvergnaud/ts-pattern/compare/v4.3.0...v5.0.0) ### TS-Pattern v5 is finally out ❤️ ### Breaking changes #### `.with` is now evaluated eagerly In the previous version of TS-Pattern, no code would execute until you called `.exhaustive()` or `.otherwise(...)`. For example, in the following code block, nothing would be logged to the console or thrown: ```ts // TS-Pattern v4 type Input = { type: 'ok'; value: number } | { type: 'error'; error: Error }; // We don't call `.exhaustive`, so handlers don't run. function someFunction(input: Input) { match(input) .with({ type: 'ok' }, ({ value }) => { console.log(value); }) .with({ type: 'error' }, ({ error }) => { throw error; }); } someFunction({ type: 'ok', value: 42 }); // nothing happens ``` In **TS-Pattern v5**, however, the library will execute the matching handler as soon as it finds it: ```ts // TS-Pattern v5 someFunction({ type: 'ok', value: 42 }); // logs "42" to the console! ``` Handlers are now evaluated **eagerly** instead of lazily. In practice, this shouldn't change anything as long as you always finish your pattern matching expressions by either `.exhaustive` or `.otherwise`. #### Matching on Maps and Sets Matching `Set` and `Map` instances using `.with(new Set(...))` and `.with(new Map(...))` is no longer supported. If you want to match specific sets and maps, you should now use the `P.map(keyPattern, valuePattern)` and `P.set(valuePattern)` patterns: ```diff - import { match } from 'ts-pattern'; + import { match, P } from 'ts-pattern'; const someFunction = (value: Set | Map) => match(value) - .with(new Set([P.number]), (set) => `a set of numbers`) - .with(new Map([['key', P.number]]), (map) => `map.get('key') is a number`) + .with(P.set(P.number), (set) => `a set of numbers`) + .with(P.map('key', P.number), (map) => `map.get('key') is a number`) .otherwise(() => null); ``` - The subpattern we provide in `P.set(subpattern)` should match all values in the set. - The value subpattern we provide in `P.map(keyPattern, subpattern)` should only match the values matching `keyPattern` for the whole `P.map(..)` pattern to match the input. ### New features #### chainable methods TS-Pattern v5's major addition is the ability to chain methods to narrow down the values matched by primitive patterns, like `P.string` or `P.number`. Since a few examples is worth a thousand words, here are a few ways you can use chainable methods: ##### P.number methods ```ts const example = (position: { x: number; y: number }) => match(position) .with({ x: P.number.gte(100) }, (value) => '🎮') .with({ x: P.number.between(0, 100) }, (value) => '🎮') .with( { x: P.number.positive().int(), y: P.number.positive().int(), }, (value) => '🎮' ) .otherwise(() => 'x or y is negative'); ``` Here is the full list of number methods: - `P.number.between(min, max)`: matches numbers between `min` and `max`. - `P.number.lt(max)`: matches numbers smaller than `max`. - `P.number.gt(min)`: matches numbers greater than `min`. - `P.number.lte(max)`: matches numbers smaller than or equal to `max`. - `P.number.gte(min)`: matches numbers greater than or equal to `min`. - `P.number.int()`: matches integers. - `P.number.finite()`: matches all numbers except `Infinity` and `-Infinity` - `P.number.positive()`: matches positive numbers. - `P.number.negative()`: matches negative numbers. ##### P.string methods ```ts const example = (query: string) => match(query) .with(P.string.startsWith('SELECT'), (query) => `selection`) .with(P.string.endsWith('FROM user'), (query) => `👯‍♂️`) .with(P.string.includes('*'), () => 'contains a star') // Methods can be chained: .with(P.string.startsWith('SET').includes('*'), (query) => `🤯`) .exhaustive(); ``` Here is the full list of string methods: - `P.string.startsWith(str)`: matches strings that start with `str`. - `P.string.endsWith(str)`: matches strings that end with `str`. - `P.string.minLength(min)`: matches strings with at least `min` characters. - `P.string.maxLength(max)`: matches strings with at most `max` characters. - `P.string.includes(str)`: matches strings that contain `str`. - `P.string.regex(RegExp)`: matches strings if they match this regular expression. ##### Global methods Some methods are available for all primitive type patterns: - `P.{..}.optional()`: matches even if this property isn't present on the input object. - `P.{..}.select()`: injects the matched value into the handler function. - `P.{..}.and(pattern)`: matches if the current pattern **and** the provided pattern match. - `P.{..}.or(pattern)`: matches if either the current pattern **or** the provided pattern match. ```ts const example = (value: unknown) => match(value) .with( { username: P.string, displayName: P.string.optional(), }, () => `{ username:string, displayName?: string }` ) .with( { title: P.string, author: { username: P.string.select() }, }, (username) => `author.username is ${username}` ) .with( P.instanceOf(Error).and({ source: P.string }), () => `Error & { source: string }` ) .with(P.string.or(P.number), () => `string | number`) .otherwise(() => null); ``` #### Variadic tuple patterns With TS-Pattern, you are now able to create array (or more accurately tuple) pattern with a variable number of elements: ```ts const example = (value: unknown) => match(value) .with( // non-empty list of strings [P.string, ...P.array(P.string)], (value) => `value: [string, ...string[]]` ) .otherwise(() => null); ``` Array patterns that include a `...P.array` are called **variadic tuple patterns**. You may only have a single `...P.array`, but as many fixed-index patterns as you want: ```ts const example = (value: unknown) => match(value) .with( [P.string, P.string, P.string, ...P.array(P.string)], (value) => `value: [string, string, string, ...string[]]` ) .with( [P.string, P.string, ...P.array(P.string)], (value) => `value: [string, string, ...string[]]` ) .with([], (value) => `value: []`) .otherwise(() => null); ``` Fixed-index patterns can also be set **after** the `...P.array` variadic, or on both sides! ```ts const example = (value: unknown) => match(value) .with( [...P.array(P.number), P.string, P.number], (value) => `value: [...number[], string, number]` ) .with( [P.boolean, ...P.array(P.string), P.number, P.symbol], (value) => `value: [boolean, ...string[], number, symbol]` ) .otherwise(() => null); ``` Lastly, argument of `P.array` is now optional, and will default to `P._`, which matches anything: ```ts const example = (value: unknown) => match(value) // 👇 .with([P.string, ...P.array()], (value) => `value: [string, ...unknown[]]`) .otherwise(() => null); ``` #### `.returnType` In TS-Pattern v4, the only way to explicitly set the return type of your `match` expression is to set the two `` type parameters of `match`: ```ts // TS-Pattern v4 match< { isAdmin: boolean; plan: 'free' | 'paid' }, // input type number // return type >({ isAdmin, plan }) .with({ isAdmin: true }, () => 123) .with({ plan: 'free' }, () => 'Oops!'); // ~~~~~~ ❌ not a number. ``` the main drawback is that you need to set the ***input type*** explicitly ***too***, even though TypeScript should be able to infer it. In TS-Pattern v5, you can use the `.returnType()` method to only set the return type: ```ts match({ isAdmin, plan }) .returnType() // 👈 new .with({ isAdmin: true }, () => 123) .with({ plan: 'free' }, () => 'Oops!'); // ~~~~~~ ❌ not a number. ``` #### What's Changed - TS-Pattern v5 base branch by [@​gvergnaud](https://togithub.com/gvergnaud) in [https://github.com/gvergnaud/ts-pattern/pull/139](https://togithub.com/gvergnaud/ts-pattern/pull/139) **Full Changelog**: https://github.com/gvergnaud/ts-pattern/compare/v4.3.0...v5.0.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 is behind base branch, or you tick the rebase/retry checkbox.

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



This PR was generated by Mend Renovate. View the repository job log.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nitic-astronomy-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2024 10:02pm