Replies: 1 comment
-
|
@psbanka this is a known TypeScript limitation in the cleanest workaround is a type assertion at the property level: import { factory, primaryKey } from '@mswjs/data';
import type { ModelDefinitionValue } from '@mswjs/data/lib/glossary';
const db = factory({
event: {
id: primaryKey(() => fakerEN.string.uuid()),
metadata: (() => ({
versionNumber: fakerEN.number.int({ min: 1, max: 100 }),
})) as unknown as ModelDefinitionValue,
},
});the alternatively, if you can flatten the structure, that avoids the typing issue entirely: const db = factory({
event: {
id: primaryKey(() => fakerEN.string.uuid()),
metadataVersionNumber: () => fakerEN.number.int({ min: 1, max: 100 }),
},
});this gap is tracked in mswjs/data#36 and should improve in a future release. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! Thanks for this amazing project. I love
mswjsand@msw/dataI am trying to define a factory with nested structures, as follows:
I did this according to this guidance in the msw/data docs.. However, this is causing typescript errors, namely:
The only way I can seem to get around this is by doing the
as unknown as anytypecast for this nested value. I couldn't find any documentation around nested structures in the how to do typescript docs.Is this the only supported way to do nested values for msw/data objects using typescript?
Beta Was this translation helpful? Give feedback.
All reactions