From 08fded8baf571dad0a5503444661a061924fbea5 Mon Sep 17 00:00:00 2001 From: hanayashiki Date: Tue, 8 Mar 2022 15:09:43 +0800 Subject: [PATCH] feat: numberField allow null or undef --- package.json | 9 ++++----- src/fields/numberField.ts | 5 ++++- src/types/infer.ts | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 583afb6..aa18a8f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "url": "https://github.com/MonoidDev/reform" }, "private": false, - "version": "1.0.0-alpha.0", + "version": "1.0.1", "license": "MIT", "publishConfig": { "access": "public" @@ -14,8 +14,8 @@ "main": "./dist/cjs/index.cjs", "module": "./dist/esm/index.mjs", "typesVersions": { - "*": { - "*": [ + ">=4.2": { + ".": [ "src/index.ts" ], "react": [ @@ -42,11 +42,10 @@ "node": ">=10" }, "scripts": { - "postinstall": "husky install", "build": "node ./esbuild.js", "dev": "node ./esbuild.js --watch", "lint": "prettier --check src/", - "prepare": "yarn build", + "prepare": "husky install && yarn build", "size": "size-limit", "analyze": "size-limit --why", "test": "yarn jest" diff --git a/src/fields/numberField.ts b/src/fields/numberField.ts index 6dee462..0f91cb9 100644 --- a/src/fields/numberField.ts +++ b/src/fields/numberField.ts @@ -13,7 +13,10 @@ export const numberField = ( const { message } = options; const numberType = any().refine((input) => { - if (typeof input === 'string' && input.trim().length === 0) { + if ( + (typeof input === 'string' && input.trim().length === 0) || + input == null + ) { return makeRight(undefined); } diff --git a/src/types/infer.ts b/src/types/infer.ts index 5afe17c..ba1a87b 100644 --- a/src/types/infer.ts +++ b/src/types/infer.ts @@ -3,6 +3,8 @@ import { Resolver } from './Resolver'; export type AnyResolver = Resolver; +export type UnknownResolver = Resolver; + export type ResolverMap = { [K in string]: AnyResolver; };