Skip to content

Commit

Permalink
fix: Fix mode enum being a number instead of a string in codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Oct 22, 2024
1 parent 1fcb95b commit 7f9e1e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package/src/createMMKV.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) {
Expand Down

0 comments on commit 7f9e1e0

Please sign in to comment.