Skip to content

Expose "toExtend" functions #36

@JacobLey

Description

@JacobLey

Alongside the existing ExpectTypeOf methods, a method to check for successful extension of types would be helpful. Perhaps a strict/branded version as well.

Proposed syntax:

expectTypeOf<5>().toExtend<number>();
expectTypeOf<unknown>().toExtend<any>();
expectTypeOf('abc').toExtend([{}]); // Typescript error

expectTypeOf<5>().toStrictExtend<number>();
expectTypeOf<unknown>().toStrictExtend<any>(); // Typescript error
expectTypeOf('abc').toStrictExtend([{}]); // Typescript error

I would be happy to submit a PR for this. Especially since the Extends and StrictExtends types are already implemented, just not directly exposed in the main method.

My current workaround is:

expectTypeOf<
     StrictExtends<Foo, Bar>
>().toBeEqual<true>();

Admittedly the grammar is a bit different (most methods start with toBe) so open to a renaming to match. toBeExtending...?

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