Skip to content

Cannot implement generic type guarding function #18202

Open
@apr-xaml

Description

@apr-xaml

TypeScript Version: 2.5.2

Code

interface ITypeChecker
{
    isOfType<T extends TBase, TBase>(obj: TBase): obj is T; 
}


class Checker implements ITypeChecker
{
    isOfType<T extends TBase, TBase>(obj: TBase): obj is T
    {
        return true;
    }

}

Expected behavior:
Class Checker should be treated as a valid implementation (used to be in Ts-2.3).
Actual behavior:
Compiler complains:

  • interface-not-properly-implemented
    (...)
    • Type predicate 'value is TBase' is not assignable to 'value is T'
      • Type 'TBase' is not assignable to type 'T'

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions