Skip to content

P.instanceOf(Text) not working with isMatching #336

@examan

Description

@examan

Describe the bug
When trying to use P.instanceOf(Text) with isMatching, TypeScript raises a type error.

Minimal reproduction

import { isMatching, P } from 'ts-pattern';

isMatching(P.instanceOf(Text), document.createTextNode('123'));

Error message

Argument of type 'Chainable<GuardP<unknown, Text>>' is not assignable to parameter of type 'KnownPattern<Text> & UnknownProperties'.
  Type 'Chainable<GuardP<unknown, Text>>' is not assignable to type '{ readonly length?: KnownPattern<number> | undefined; readonly normalize?: KnownPattern<() => void> | undefined; readonly wholeText?: KnownPattern<string> | undefined; ... 62 more ...; readonly assignedSlot?: KnownPattern<...> | undefined; } & UnknownProperties'.
    Type 'Chainable<GuardP<unknown, Text>>' is not assignable to type 'UnknownProperties'.
      Index signature for type 'string' is missing in type 'Matcher<unknown, Text, "default", None, Text> & Omit<{ optional<input>(): Chainable<OptionalP<input, GuardP<unknown, Text>>, "optional">; and<input, const p2 extends Pattern<...>>(pattern: p2): Chainable<...>; or<input, const p2 extends Pattern<...>>(pattern: p2): Chainable<...>; select<input>(): Chainable<...>; sel...'.(2345)

Expected behavior
isMatching(P.instanceOf(Text), document.createTextNode('123')) should compile and return true.

TypeScript playground with a minimal reproduction case

Playground

Versions

  • TypeScript version: 5.9.3
  • ts-pattern version: 5.9.0
  • environment: node 22.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions