Skip to content

Type mismatch on intersection of object and union #68

@kuuote

Description

@kuuote

I want to define following object.

import { is } from "https://deno.land/x/unknownutil@v3.17.0/mod.ts";

export const isResponse = is.IntersectionOf([
  is.ObjectOf({
    id: is.String,
  }),
  is.UnionOf([
    is.ObjectOf({
      result: is.String,
    }),
    is.ObjectOf({
      error: is.String,
    }),
  ]),
]); 

but occurs this error.

error: TS2345 [ERROR]: Argument of type '[Predicate<{ id: string; }> & WithMetadata<IsObjectOfMetadata>, Predicate<{ result: string; } | { error: string; }> & WithMetadata<...>]' is not assignable to parameter of type 'readonly [Predicate<unknown> & WithMetadata<IsObjectOfMetadata>, ...(Predicate<unknown> & WithMetadata<IsObjectOfMetadata>)[]]'.
  Type at position 1 in source is not compatible with type at position 1 in target.
    Type 'Predicate<{ result: string; } | { error: string; }> & WithMetadata<IsUnionOfMetadata>' is not assignable to type 'Predicate<unknown> & WithMetadata<IsObjectOfMetadata>'.
      Type 'Predicate<{ result: string; } | { error: string; }> & WithMetadata<IsUnionOfMetadata>' is not assignable to type 'WithMetadata<IsObjectOfMetadata>'.
        The types of '[metadataKey].name' are incompatible between these types.
          Type '"isUnionOf"' is not assignable to type '"isObjectOf"'.
export const isResponse = is.IntersectionOf([

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions