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
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
export type Prettify<T> = any extends T
? T // preserve any/unknown
: { [K in keyof T]: T[K] } & {};
export type ValidationResult<T> = {
isValid: true
value: T
Expand Down
31 changes: 31 additions & 0 deletions src/predicates/any.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
import {test} from 'kizu';
import {any} from './any';
import {object, string} from '.';
import type {Infer} from '..';

// Type-level test: Infer<any()> should be `any`, not `{ [x: string]: any }`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const anyValidator = any();

type AnyType = Infer<typeof anyValidator>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const anyTest1: AnyType = 'string'; // should work - any accepts string
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const anyTest2: AnyType = 42; // should work - any accepts number
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const anyTest3: AnyType = {foo: 'bar'}; // should work - any accepts object

// Type-level test: any() in object schema should allow any value
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const schema = object({
name: string(),
metadata: any(),
});

type Schema = Infer<typeof schema>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const schemaTest1: Schema = {name: 'test', metadata: 'anything'};
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const schemaTest2: Schema = {name: 'test', metadata: 123};
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-underscore-dangle
const schemaTest3: Schema = {name: 'test', metadata: {nested: 'object'}};

test('any(): accepts any value', (assert) => {

Expand Down