Effect CommunityEC
Effect Community2y ago
5 replies
BinaryArtifex

TypeScript Error with Schema Fields in TaggedRequest

it seems abit odd that i can't just pass a schema as the fields argument to a Schema.TaggedRequest...

export const LoginArgs = Schema.struct({
  username: EmailAddress,
  password: Schema.NonEmpty,
});

export class LoginRequest extends Schema.TaggedRequest<LoginRequest>()(
  "LoginRequest",
  AuthServiceError,
  Session,
  LoginArgs
) {}


the LoginArgs in the LoginRequest gives me the following TS error...

Argument of type 'struct<{ username: Schema<string, string, never>; password: $string; }>' is not assignable to parameter of type 'Fields'.
  Index signature for type 'string' is missing in type 'struct<{ username: Schema<string, string, never>; password: $string; }>'


probably me trying to push the effect friendship here, but is there also any way to pass a Schema.Class as the fields argument? ive gotten use to abstracting away the decode functionality in my schemas...

export class LoginArgs extends Schema.Class<LoginArgs>("LoginArgs")({
  username: EmailAddress,
  password: Schema.NonEmpty,
}) {
  static decode = Schema.decodeUnknown(LoginArgs);
}

export class LoginRequest extends Schema.TaggedRequest<LoginRequest>()(
  "LoginRequest",
  AuthServiceError,
  Session,
  LoginArgs
) {}


the latter LoginArgs shows this TS error...

Argument of type 'typeof LoginArgs' is not assignable to parameter of type 'Fields'.
  Index signature for type 'string' is missing in type 'typeof LoginArgs'.
Was this page helpful?