Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

[Bug] Exported type for expect function #8

Closed
FTWinston opened this issue Dec 23, 2021 · 2 comments
Closed

[Bug] Exported type for expect function #8

FTWinston opened this issue Dec 23, 2021 · 2 comments
Labels
bug Something isn't working released This issue/pull request has been released.

Comments

@FTWinston
Copy link
Contributor

FTWinston commented Dec 23, 2021

Describe the bug

Using expect, as exported by @storybook/jest, triggers failures in the @typescript-eslint/no-unsafe-member-access and @typescript-eslint/no-unsafe-call rules. Using the @storybook/expect version does not.

Confusingly, if I create a local copy of all of the @storybook/jest and call that version instead, this works correctly.

Steps to reproduce the behavior

  1. Ensure project has eslint running, using plugin:@typescript-eslint/recommended
  2. Create a new story, and in its play function, call expect from @storybook/expect.
  3. Note that no eslint errors are shown.
  4. Replace import expect from '@storybook/expect' with import { expect } from '@storybook/jest'
  5. Not that expect calls now show eslint errors for @typescript-eslint/no-unsafe-member-access and @typescript-eslint/no-unsafe-call
  6. Copy all of @storybook/jest's code into a local jest.ts file, and replace import { expect } from '@storybook/jest' with import { expect } from './jest'
  7. Note that no eslint errors are shown.

Expected behavior

None of the three cases described above should show these eslint errors.

The exported type definitions for @storybook/jest are:

import * as mock from 'jest-mock';
export declare const jest: typeof mock;
export declare const expect: import("expect/build/types").Expect<import("expect/build/types").MatcherState>;

Eslint (as well as VSCode's intellisense) seems to interpret the type of this expect as any.

It should instead have the same type as the expect exported from @storybook/expect (and it does... but only if I copy the @storybook/jest code locally).

Screenshots and/or logs

For this line:
expect(canvas.queryByText('Message')).not.toBeNull();

We get

  Line 40:5:  Unsafe member access .not on an `any` value  @typescript-eslint/no-unsafe-member-access
  Line 40:5:  Unsafe call of an `any` typed value          @typescript-eslint/no-unsafe-call
  Line 40:5:  Unsafe call of an `any` typed value          @typescript-eslint/no-unsafe-call

Environment

  • OS: Windows
  • Node.js version: v16.13.0
  • NPM version: 8.1.0
  • Browser (if applicable): N/A
  • Browser version (if applicable): N/A
  • Device (if applicable): N/A

Additional context

Possibly caused by the esm compile target being ES5? I'll try and check this.

@FTWinston FTWinston added the bug Something isn't working label Dec 23, 2021
@FTWinston FTWinston changed the title [Bug] Type of exported expected function [Bug] Type of exported expect function Dec 23, 2021
@FTWinston FTWinston changed the title [Bug] Type of exported expect function [Bug] Exported type for expect function Dec 23, 2021
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

🚀 Issue was released in v0.0.6 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Feb 4, 2022
@yannbf
Copy link
Member

yannbf commented Feb 4, 2022

Fixed in #9. Thanks a lot @FTWinston!

@yannbf yannbf closed this as completed Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working released This issue/pull request has been released.
Projects
None yet
Development

No branches or pull requests

2 participants