Introduce the core builder and pattern constructors:
- match(value): chain .with(pattern, handler) and terminate with
.exhaustive() (throws on no match) or .otherwise(handler).
- P.literal, P.type, P.when, P.any, P.shape for pattern construction.
- Each pattern is a Matcher<T> whose matches acts as a type guard, so
handler parameters are narrowed to the matched type.
The MatchBuilder accumulates handlers and returns a new builder per
.with() call (immutable chaining); finalization runs the cases in order
and returns the first match's handler result.
TypeScript configuration relaxed in .oxlintrc.json:
- Disable eslint/no-undefined (we use undefined as the no-match sentinel)
- Disable eslint/sort-keys (handler order matters; alphabetical would
be wrong)
- Disable eslint/id-length (T/R/U/V generics are standard TS convention)
- Disable import/no-named-export (false positive for library entry points)
Verified:
- tsc --noEmit passes with strict + noUncheckedIndexedAccess
- tsc -p tsconfig.build.json emits dist/*.js + .d.ts + sourcemaps
- node -e "import('./dist/index.js')" loads and exposes { match, P }
38 lines
890 B
JSON
38 lines
890 B
JSON
{
|
|
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
"plugins": [
|
|
"typescript",
|
|
"unicorn",
|
|
"oxc",
|
|
"import"
|
|
],
|
|
"categories": {
|
|
"correctness": "error",
|
|
"suspicious": "error",
|
|
"perf": "warn",
|
|
"style": "warn",
|
|
"restriction": "error",
|
|
"nursery": "off"
|
|
},
|
|
"rules": {
|
|
"eslint/no-undefined": "off",
|
|
"eslint/sort-keys": "off",
|
|
"eslint/id-length": "off",
|
|
"import/no-named-export": "off"
|
|
},
|
|
"env": {
|
|
"builtin": true,
|
|
"es2024": true,
|
|
"node": true
|
|
},
|
|
"overrides": [
|
|
{
|
|
"files": ["**/*.test.ts"],
|
|
"rules": {
|
|
"no-unused-expressions": "off",
|
|
"no-empty-file": "off"
|
|
}
|
|
}
|
|
],
|
|
"ignorePatterns": ["dist", "node_modules", "coverage"]
|
|
} |