Skip to content

Commit

Permalink
fix: some strict fn type improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Dec 4, 2020
1 parent d5c5391 commit 8092218
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Condition.ts
Expand Up @@ -68,7 +68,7 @@ class Condition<T extends SchemaLike = SchemaLike> {
ref.getValue(options?.value, options?.parent, options?.context),
);

let schema = this.fn.apply(base, values.concat(base, options));
let schema = this.fn.apply(base, values.concat(base, options) as any);

if (schema === undefined || schema === base) return base;

Expand Down
2 changes: 1 addition & 1 deletion src/number.ts
@@ -1,6 +1,6 @@
import { MixedLocale, number as locale } from './locale';
import isAbsent from './util/isAbsent';
import type { AnyObject, Maybe } from './types';
import type { AnyObject, Maybe, Message } from './types';
import type Reference from './Reference';
import type { Defined, If, Thunk } from './util/types';
import BaseSchema from './schema';
Expand Down
5 changes: 4 additions & 1 deletion src/object.ts
Expand Up @@ -27,7 +27,10 @@ export type Assign<T extends {}, U extends {}> = {

export type AnyObject = Record<string, any>;

export type ObjectShape = Record<string, AnySchema | Reference | Lazy<any>>;
export type ObjectShape = Record<
string,
AnySchema | Reference | Lazy<any, any>
>;

export type DefaultFromShape<Shape extends ObjectShape> = {
[K in keyof Shape]: Shape[K] extends ObjectSchema<infer TShape>
Expand Down
6 changes: 3 additions & 3 deletions src/util/createValidation.ts
Expand Up @@ -13,7 +13,7 @@ import type { AnySchema } from '../schema';

export type CreateErrorOptions = {
path?: string;
message?: Message;
message?: Message<any>;
params?: ExtraParams;
type?: string;
};
Expand Down Expand Up @@ -45,7 +45,7 @@ export type TestOptions<TSchema extends AnySchema = AnySchema> = {

export type TestConfig<TValue = unknown, TContext = {}> = {
name?: string;
message?: Message;
message?: Message<any>;
test: TestFunction<TValue, TContext>;
params?: ExtraParams;
exclusive?: boolean;
Expand All @@ -59,7 +59,7 @@ export default function createValidation(config: {
name?: string;
test: TestFunction;
params?: ExtraParams;
message?: Message;
message?: Message<any>;
}) {
function validate<TSchema extends AnySchema = AnySchema>(
{
Expand Down
3 changes: 3 additions & 0 deletions test/types.ts
Expand Up @@ -79,6 +79,9 @@ string().required().nullable();
lazy: lazy(() => number().required()),
});

const foo = object({
string: string().default(''),
});
// type F = StringSchema<string>;
// type f = F extends TypedSchema ? F['__inputType'] : false;

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -2,7 +2,8 @@
"extends": "@4c/tsconfig/web",
"compilerOptions": {
"allowJs": true,
"rootDir": "src"
"rootDir": "src",
"strictFunctionTypes": true
},
"include": ["src"]
}

0 comments on commit 8092218

Please sign in to comment.