Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ runtyp is designed for speed. Here's how it compares to other popular programmat
npm i runtyp
```

## Requirements

- **Node.js**: 18+ (or any modern browser)
- **TypeScript**: 5.0+ (for type inference features)

> **Note**: JavaScript users can use runtyp without TypeScript. The TypeScript requirement only applies if you want type inference via `Infer<>`.

# Usage

## Example
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"lint": "eslint ./ --ext .js,.ts",
"build": "tsc"
},
"peerDependencies": {
"typescript": ">=5.0.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
Expand Down
13 changes: 13 additions & 0 deletions src/predicates/literal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import {test} from 'kizu';
import {literal} from './literal';
import type {Infer} from '..';

// Type-level test: Infer should preserve literal types
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const textValidator = literal('text');

type TextType = Infer<typeof textValidator>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const typeTest: TextType = 'text';
// @ts-expect-error - 'other' is not assignable to 'text'
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const typeTestFail: TextType = 'other';

test('literal(): valid inputs', (assert) => {

Expand Down
2 changes: 1 addition & 1 deletion src/predicates/literal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Pred, ValidationResult} from '..';

export function literal<T extends any>(expected: T): Pred<T> {
export function literal<const T>(expected: T): Pred<T> {

return (value: unknown): ValidationResult<T> => {

Expand Down