Skip to content

Unexpected satisfies error for nested function #1342

@ocavue

Description

@ocavue

I have two type definitions. One uses pure TypeScript, while the other uses valibot. I want to make sure that these two types are in sync, so we utilize the satisfies technique from #3.

I found an unexpected satisfies error in my code, as shown below.

Playground link

import * as v from 'valibot';

type GenericOutputSchema<TOutput> = v.BaseSchema<
  unknown,
  TOutput,
  v.BaseIssue<unknown>
>;

export type LogLevel = 'info' | 'debug' | 'warn';
export const LogLevelSchema = v.union([
  v.literal('debug'),
  v.literal('info'),
  v.literal('warn'),
]) satisfies GenericOutputSchema<LogLevel>;

export type LogHandler = (level: LogLevel) => void;
export const LogHandlerSchema = v.pipe(
  v.function(),
  v.args(v.tuple([LogLevelSchema])),
  v.returns(v.void()),
) satisfies GenericOutputSchema<LogHandler>;

export type OnLog = (logHandler: LogHandler) => void;
export const OnLogSchema = v.pipe(
  v.function(),
  v.args(v.tuple([LogHandlerSchema])),
  v.returns(v.void()),
) satisfies GenericOutputSchema<OnLog>;
//~~~~~~~~~
//Type 'SchemaWithPipe<readonly [FunctionSchema<undefined>, ArgsAction<(...args: unknown[]) => unknown, TupleSchema<[SchemaWithPipe<readonly [FunctionSchema<undefined>, ArgsAction<(...args: unknown[]) => unknown, TupleSchema<[UnionSchema<[LiteralSchema<"debug", undefined>, LiteralSchema<...>, LiteralSchema<...>], undefined>...' does not satisfy the expected type 'GenericOutputSchema<OnLog>'.
//  Types of property '"~standard"' are incompatible.
//    Type 'StandardProps<(...args: unknown[]) => unknown, (args_0: (...args: unknown[]) => unknown) => void>' is not assignable to type 'StandardProps<unknown, OnLog>'.
//      Type '(args_0: (...args: unknown[]) => unknown) => void' is not assignable to type 'OnLog'.
//        Types of parameters 'args_0' and 'logHandler' are incompatible.
//          Type 'LogHandler' is not assignable to type '(...args: unknown[]) => unknown'.
//            Types of parameters 'level' and 'args' are incompatible.
//              Type 'unknown' is not assignable to type 'LogLevel'. (1360)

export {};

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions