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
Typescript:schema type error #120
Comments
The problem here is that typings of JSONSchema expect a subset of strings to be used as a type value ( In order to be able to use it in the schema option you just need to ensure TS the schema object is not going to be mutated. You can do it in two ways.
const schema = { ... } as const
const store = new ElectronStore({ schema: { /* your schema */ } }) |
@mateuszkocz |
Or you may use interface like this export interface Schema {
someString: string;
someListOfStrings: Array<string>
}
const store = new Store<Schema>() |
Option 1 here didn't quite work for me, because Option 2 didn't work because I wanted to access things in my schema, like using the minimum/maximum for numeric inputs, and inlining the object like that prevents me from doing so. Using an interface and electron-store's Ultimately I combined these: use const schema = {
// ...
} as const;
// https://stackoverflow.com/a/43001581
type DeepWriteable<T> = { -readonly [P in keyof T]: DeepWriteable<T[P]> };
const store = new Store({ schema: schema as DeepWriteable<typeof schema> }); |
Version:
electron-store: 5.1.1
typescript:3.9.4
node:14.3.0
electron:9.0.0
The text was updated successfully, but these errors were encountered: