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

Definition for Objects with dynamic keys #252

Open
brogine opened this issue Nov 18, 2022 · 3 comments
Open

Definition for Objects with dynamic keys #252

brogine opened this issue Nov 18, 2022 · 3 comments

Comments

@brogine
Copy link

brogine commented Nov 18, 2022

Hi everyone!

First of all, thanks a lot for this project. It was the missing feature that MSW was lacking.
So far I've found it easy to use and extremely simple to setup.

Let me describe the issue that I'm facing at the moment.
I was not able to find a way to describe an estructure with dynamic object keys.
Let's say I've this in TS:

{
  models: {
    [key: string]: {
      attr: number
      attr2: string
    }
  }
}

Is there a way to do it? I tried adding Object as a type, but when I create elements, they are created as an empty object.
Please, let me know if this is a missing feature. I'll try to create a PR for it.

@kettanaito
Copy link
Member

Hey, @brogine. Thanks for your kind words!

Dynamic object property support is not currently present. Moreover, I can't say for certain how it would align with the current API. If you have some proposals on this, I'd be glad to support you in making this happen. But if this support implies rewriting the library, I'd recommend against it, as I'm in a middle of such a rewrite already (that's been going on for quite some time but it's destined to land eventually).

@manzaloros
Copy link

I have this same issue.

Basically I have a field on a model that is an array of objects that can be one of 2 types.

But there is no way in mswjs/data to model an object that can have variable properties.

@timtos
Copy link

timtos commented Mar 5, 2024

Any updates on this? I have a Record<string, string> type that wants to be mocked. :)

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

No branches or pull requests

4 participants