Skip to content

[Feature]: typesafe assertions #13334

@DetachHead

Description

@DetachHead

🚀 Feature Proposal

this will always fail, but since typescript infers the type as unknown, there's no compile error:

expect('foo').toBe(1) // no error
expect<string>('foo').toBe(1) // no error

Motivation

it will allow you to identify errors in your tests much earlier, speeding up development 🚀🚀🚀

Example

// the new and improved expect 🚀:
declare const expect: <T>(actual: T) => { toBe: (expected: T) => void}

// usage:
expect('foo').toBe(1) // TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

Pitch

the current expect types make using typescript with jest pretty much useless. i think if jest is going to support typescript, it should support basic functionality like this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions