Skip to content

[Feature]: Export MockedObject & similar utility types? #12784

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

🚀 Feature Proposal

Could TypeScript types such as MockedObject please be exported from some package that consumers would have access to while using the @jest/globals package?

Motivation

It'd be convenient for declaring types of objects that contain mocks. Right now there's now easy way to declare in the type system that an object is a MockedObject<T> for any T object type.

Example

In typescript-eslint/tslint-to-eslint-config#1458 I'm trying to get the TypeScript types to work for a createStubWritableStream function that returns a mocked version of a NodeJS.WritableStream. Here's a minimum reproduction in the TypeScript playground.

Pitch

MockedObject isn't exported in any way I can find -nor documented on the website-. There's no way to declare the return type of createStubWritableStream -or variables that store that value type- to be MockedObject<NodeJS.WritableStream>.

Even if I'm using jest.fn() and/or the types wrong, being able to refer to MockedObject<...> is quite useful for debugging type system woes such as this one.

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