Skip to content

Defining a type predicate breaks inheritance for methods with mapped typesΒ #56133

@johnw42

Description

@johnw42

πŸ”Ž Search Terms

type predicate mapped

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type system behavior

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/IYIwzgLgTsDGEAJYBthjAgglEBLawUAngDwAqAfAgN4BQCCokM8SwAdgMoAWUu7AawDq+bgHsArhADCY9hACmADwgAKAG7BkEhQC4EEwezEB3dgEp9m7QoS4MZANy16jcAVZKiAL2+kAqhjKiuwAJhiGAsZmANoAuhSqrgxK+tQIMQDSduwIAgpEYgBmCIFx+oFZcQgAvgA0rpZYOPgwxCSBFM41LkweiChoGACyRNh4BO2UCMEKYRjjrYSk03QMfSyIXr4BQSpz4QZGpuzxickIqTQZ2fx5BcWlYOVPVbUNDE2Lk7tdtD1AA

πŸ’» Code

abstract class Arbitrary<T> {
  abstract canShrinkWithoutContext(value: unknown): value is T;

  abstract xyzzy<Us extends unknown[]>(
    x: { [K in keyof Us]: Us[K] },
  ): Arbitrary<Us>;
}

abstract class MyArbitrary<T> extends Arbitrary<T> {
  abstract xyzzy<Us extends unknown[]>(
    x: { [K in keyof Us]: Us[K] },
  ): Arbitrary<Us>;
}

πŸ™ Actual behavior

The compiler reports an error in MyArbitrary unless canShrinkWithoutContext is removed or its return type is changed.

πŸ™‚ Expected behavior

The xyzzy method should be overridden in the derived class.

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions