From 7f9e1e081de91726f5737b420fcf56978981950b Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 22 Oct 2024 11:14:31 +0200 Subject: [PATCH] fix: Fix `mode` enum being a number instead of a string in codegen --- package/src/createMMKV.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package/src/createMMKV.ts b/package/src/createMMKV.ts index f607847d..2cc31c39 100644 --- a/package/src/createMMKV.ts +++ b/package/src/createMMKV.ts @@ -1,5 +1,5 @@ import { Platform } from 'react-native'; -import { getMMKVTurboModule, type Configuration } from './NativeMmkv'; +import { getMMKVTurboModule, Mode, type Configuration } from './NativeMmkv'; import type { NativeMMKV } from './Types'; import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext'; @@ -23,6 +23,13 @@ export const createMMKV = (config: Configuration): NativeMMKV => { } } + if (typeof config.mode === 'number') { + // Code-gen expects enums to be strings. In TS, they might be numbers tho. + // This sucks, so we need a workaround. + // @ts-expect-error the native side actually expects a string. + config.mode = Mode[config.mode]; + } + const instance = module.createMMKV(config); if (__DEV__) { if (typeof instance !== 'object' || instance == null) {