ts-pattern
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { Pattern } from './types/Pattern.js'; | ||
import { Pattern, UnknownProperties } from './types/Pattern.js'; | ||
import * as P from './patterns.js'; | ||
@@ -32,2 +32,2 @@ /** | ||
*/ | ||
export declare function isMatching<const T, const P extends P.Pattern<NoInfer<T>>>(pattern: P, value: T): value is P.infer<P>; | ||
export declare function isMatching<const T, const P extends P.Pattern<T> & UnknownProperties>(pattern: P, value: T): value is P.infer<P>; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* The `P` module contains patterns for primitive types, wildcards and | ||
* other pattern-matching utilities. | ||
* | ||
* @module | ||
*/ | ||
import * as symbols from './internals/symbols.js'; | ||
@@ -7,6 +13,18 @@ import { matcher } from './internals/symbols.js'; | ||
import { Pattern, UnknownPattern, OptionalP, ArrayP, MapP, SetP, AndP, OrP, NotP, GuardP, SelectP, AnonymousSelectP, GuardExcludeP, CustomP, StringPattern, AnyPattern, NumberPattern, BooleanPattern, BigIntPattern, NullishPattern, SymbolPattern, Chainable, ArrayChainable, NonNullablePattern } from './types/Pattern.js'; | ||
export type { Pattern, Fn as unstable_Fn }; | ||
export type { | ||
/** | ||
* `Pattern<T>` is the type of all patterns | ||
* that can match a value of type `T`. | ||
*/ | ||
Pattern, | ||
/** | ||
* `unstable_Fn` can be used to created a | ||
* a Matchable instance – a custom type that | ||
* can be used as a pattern. | ||
* | ||
* @experimental This feature is unstable. | ||
*/ | ||
Fn as unstable_Fn, }; | ||
export { matcher }; | ||
/** | ||
* @experimental | ||
* A `Matchable` is an object implementing | ||
@@ -16,3 +34,3 @@ * the Matcher Protocol. It must have a `[P.matcher]: P.Matcher<NarrowFn>` | ||
* | ||
* Note that this api is unstable. | ||
* @experimental This feature is unstable. | ||
* | ||
@@ -28,7 +46,6 @@ * @example | ||
/** | ||
* @experimental | ||
* A `Matcher` is an object with `match` function, which | ||
* defines how this object should be matched by TS-Pattern. | ||
* | ||
* Note that this api is unstable. | ||
* @experimental This feature is unstable. | ||
* | ||
@@ -35,0 +52,0 @@ * @example |
@@ -46,5 +46,6 @@ import type * as symbols from '../internals/symbols.js'; | ||
} | ||
export type UnknownPattern = readonly [] | readonly [unknown, ...unknown[]] | readonly [...unknown[], unknown] | { | ||
readonly [k: string]: unknown; | ||
} | Primitives | UnknownMatcher; | ||
export type UnknownProperties = { | ||
readonly [k: PropertyKey]: unknown; | ||
}; | ||
export type UnknownPattern = readonly [] | readonly [unknown, ...unknown[]] | readonly [...unknown[], unknown] | UnknownProperties | Primitives | UnknownMatcher; | ||
/** | ||
@@ -51,0 +52,0 @@ * `Pattern<a>` is the generic type for patterns matching a value of type `a`. A pattern can be any (nested) javascript value. |
{ | ||
"name": "ts-pattern", | ||
"version": "5.6.0", | ||
"version": "5.6.1", | ||
"description": " The exhaustive Pattern Matching library for TypeScript.", | ||
@@ -39,2 +39,3 @@ "type": "module", | ||
"prepublishOnly": "npm run test && npm run build", | ||
"publish:jsr": "npm run prepublishOnly && npx jsr publish", | ||
"test": "jest", | ||
@@ -41,0 +42,0 @@ "clear-test": "jest --clearCache", |
@@ -75,37 +75,20 @@ <h1 align="center">TS-Pattern</h1> | ||
Via yarn | ||
You can also use your favorite package manager: | ||
``` | ||
pnpm add ts-pattern | ||
# OR | ||
yarn add ts-pattern | ||
``` | ||
Via pnpm | ||
``` | ||
pnpm add ts-pattern | ||
``` | ||
Via Bun | ||
``` | ||
# OR | ||
bun add ts-pattern | ||
# OR | ||
npx jsr add @gabriel/ts-pattern | ||
``` | ||
### Compatibility with different TypeScript versions | ||
## Want to become a TypeScript Expert? | ||
TS-Pattern assumes that [Strict Mode](https://www.typescriptlang.org/tsconfig#strict) is enabled in your `tsconfig.json` file. | ||
Check out 👉 [Type-Level TypeScript](https://type-level-typescript.com/), an online course teaching you how to unleash the full potential of TypeScript's Turing-complete type system. You already know how to code, and types are simply another programming language to master. This course bridges the gap, helping you apply your existing programming knowledge to TypeScript's type system, so you never again struggle with type errors or feel unable to type complex generic code correctly! | ||
| ts-pattern | TypeScript v5+ | TypeScript v4.5+ | TypeScript v4.2+ | | ||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ---------------- | ---------------- | | ||
| v5.x [(Docs)](#documentation) [(Migration Guide)](https://github.com/gvergnaud/ts-pattern/tree/master/docs/v4-to-v5-migration-guide.md) | ✅ | ❌ | ❌ | | ||
| v4.x [(Docs)](https://github.com/gvergnaud/ts-pattern/tree/v4##documentation) [(Migration Guide)](https://github.com/gvergnaud/ts-pattern/tree/master/docs/v3-to-v4-migration-guide.md) | ✅ | ✅ | ❌ | | ||
| v3.x [(Docs)](https://github.com/gvergnaud/ts-pattern/tree/v3#documentation) | ✅ | ✅ | ✅ | | ||
Type-Level TypeScript takes you on a deep dive into the most advanced features of the type system. By the end of this journey, you'll emerge as one of your company's best TypeScript developers. You'll know how to craft elegant code and create developer-friendly libraries that your colleagues will love using! | ||
- ✅ Full support | ||
- ❌ Not supported | ||
## Want to get better at TypeScript? | ||
Check out 👉 [Type-Level TypeScript](https://type-level-typescript.com/), my online course teaching how to take full advantage of the most advanced features of TypeScript. You will learn everything there is to know to build awesome libraries with great developer experiences and become a real TypeScript expert in the process! | ||
# Documentation | ||
@@ -112,0 +95,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
418558
0.36%1502
1.21%1649
-1.02%