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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSW/Faker - arrays of enum values are not generating properly #1660

Open
dteske25 opened this issue Oct 9, 2024 · 3 comments
Open

MSW/Faker - arrays of enum values are not generating properly #1660

dteske25 opened this issue Oct 9, 2024 · 3 comments
Labels
mock Related to mock generation msw MSW related issues

Comments

@dteske25
Copy link
Contributor

dteske25 commented Oct 9, 2024

What are the steps to reproduce this issue?

I was able to get a minimal repro stood up:
https://stackblitz.com/edit/vitejs-vite-xqak8w?file=src%2Fhandlers%2Fexample.ts&view=editor

What happens?

It looks like for some reason the fake type is being generated as an array of array of enums instead of just the array of enums that it should be.

What were you expecting to happen?

Any logs, error output, etc?

Here's the typescript error that's also visible in the IDE

 ❯ npm run build

> [email protected] build
> tsc -b && vite build

src/handlers/example.ts:36:3 - error TS2322: Type '(2 | 1 | 3)[][] | undefined' is not assignable to type 'ExampleEnum[] | null | undefined'.
  Type '(2 | 1 | 3)[][]' is not assignable to type 'ExampleEnum[]'.
    Type '(2 | 1 | 3)[]' is not assignable to type 'ExampleEnum'.

36   exampleProperty: faker.helpers.arrayElement([
     ~~~~~~~~~~~~~~~

  src/handlers/example.ts:22:3
    22   exampleProperty?: ExampleEnum[] | null;
         ~~~~~~~~~~~~~~~
    The expected type comes from property 'exampleProperty' which is declared here on type 'ExampleResponse'


Found 1 error.

Any other comments?

What versions are you using?

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  npmPackages:
    @tanstack/react-query: ^5.56.2 => 5.56.2 
    axios: ^1.7.7 => 1.7.7 
    msw: ^2.4.9 => 2.4.9 
    orval: ^7.1.1 => 7.1.1 
    react: ^18.3.1 => 18.3.1
@melloware melloware added mock Related to mock generation msw MSW related issues labels Oct 10, 2024
@Hypenate
Copy link
Contributor

We have the same issue with 7.2.0.

This is generated:

import {
  ChangeType
} from './schemas'

This is the error:

TS2724: './ schemas' has no exported member named ChangeType. Did you mean ChangeTypeDto

This is our a part of our override:

      override: {
        components: {
          schemas: {
            suffix: 'Dto',
          },
        },
      },

@melloware
Copy link
Collaborator

Any help looking through the MSW code where the issue is and providing a PR would be great!

@gegorov
Copy link

gegorov commented Nov 25, 2024

same issue happens in 7.3.0, it seems that MSW generator doesn't respect override.components.schemas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mock Related to mock generation msw MSW related issues
Projects
None yet
Development

No branches or pull requests

4 participants