Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

expectTypeOf allows an incorrect any value instead of the specified type #4205

Open
6 tasks done
kwangure opened this issue Oct 1, 2023 · 2 comments
Open
6 tasks done
Labels

Comments

@kwangure
Copy link

kwangure commented Oct 1, 2023

Describe the bug

When I use expectTypeOf, I expect it to fail when I pass any as input. For example, toBeString() should strictly only allow strings and not any other type...including any.

expectTypeOf(1).toBeString(); //  Fails 馃憤
expectTypeOf(1 as any).toBeString(); // Passes 馃憥

This is particular useful in cases when your types reason about any, I need to strictly know that a type will fail if its any or not. For example:

type IsAny<T> = 0 extends 1 & T ? true : false;

export type CustomType<T> = IsAny<T> extends true ? number: any;

If I use CustomType somewhere, I'd like to test expectTypeOf(value).toBeNumber(); and have it fail if it's any when I don't expect it to be.

Reproduction

expectTypeOf(1).toBeString(); //  Fails 馃憤
expectTypeOf(1 as any).toBeString(); // Passes 馃憥

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
    Memory: 683.74 MB / 3.69 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.4.0 - ~/.nvm/versions/node/v20.4.0/bin/node
    npm: 9.7.2 - ~/.nvm/versions/node/v20.4.0/bin/npm
    pnpm: 8.7.1 - ~/.nvm/versions/node/v20.4.0/bin/pnpm
  npmPackages:
    vite: ^4.4.8 => 4.4.9 
    vitest: ^0.33.0 => 0.33.0

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

These type assertions are provided by https://github.com/mmkal/expect-type

Please, make an issue there.

@kwangure
Copy link
Author

kwangure commented Oct 3, 2023

This was resolved in mmkal/expect-type#38 and addition to Vitest is pending in #4206.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants