admin管理员组文章数量:1296489
I'm using electron-store
for a demo electron project. In my main.ts
process, I'm attempting to initialize the store and retrieve a simple settings object. It looks like this:
// main.ts
import Store, { Schema } from 'electron-store';
type settingsType = {
settings: {
environment: 'development' | 'test' | 'prod',
refreshInterval: number,
}
}
const schema: Schema<settingsType> = {
settings: {
type: 'object',
properties: {
environment: {
type: 'string',
enum: ['development', 'test', 'prod'],
default: 'development',
},
refreshInterval: {
type: 'number',
minimum: 10000, // ten seconds
maximum: 600000, // ten min
default: 60000, // one min
}
},
default: {},
required: ['environment', 'refreshInterval'],
}
}
const store = new Store<settingsType>({schema});
// ERROR: TS2339: Property 'get' does not exist on type 'ElectronStore<settingsType>'.
let settingsStore: settingsType = store.get('settings');
I think I'm defining everything as expected, but I'm still getting a TS
error from the store.get
call. What am I missing?
I'm using electron-store
for a demo electron project. In my main.ts
process, I'm attempting to initialize the store and retrieve a simple settings object. It looks like this:
// main.ts
import Store, { Schema } from 'electron-store';
type settingsType = {
settings: {
environment: 'development' | 'test' | 'prod',
refreshInterval: number,
}
}
const schema: Schema<settingsType> = {
settings: {
type: 'object',
properties: {
environment: {
type: 'string',
enum: ['development', 'test', 'prod'],
default: 'development',
},
refreshInterval: {
type: 'number',
minimum: 10000, // ten seconds
maximum: 600000, // ten min
default: 60000, // one min
}
},
default: {},
required: ['environment', 'refreshInterval'],
}
}
const store = new Store<settingsType>({schema});
// ERROR: TS2339: Property 'get' does not exist on type 'ElectronStore<settingsType>'.
let settingsStore: settingsType = store.get('settings');
I think I'm defining everything as expected, but I'm still getting a TS
error from the store.get
call. What am I missing?
2 Answers
Reset to default 11Try to downgrade electron-store
version to 8.2.0
npm i [email protected]
. It helped in my case.
Aside from downgrading, adding "moduleResolution": "node16"
to your tsconfig should also fix this issue. Also you will need to add a corresponding pilerOption.module
to your tsconfig, just for good measures.
But then you will need to make sure you have "type": "module"
in you package.json. Which may break, or fix, other package imports in your project. Plus you will probably need to modify your preload path when calling new BrowserWindow()
to import an mjs file instead of a js one for your preload script like so: preload: join(__dirname, '../preload/index.mjs')
.
And if you make these changes, import paths will now need explicit file extensions so /code.js
instead of /code
. Plus keep in mind that global variables will now be shared so you may run into issues redeclaring vars. And in general your code will be piled drastically different than it was before... so keep that in mind.
Or just downgrade if that works for you.
本文标签: javascriptelectronstore returns quotProperty 39set3939get39 does not exist on typequotStack Overflow
版权声明:本文标题:javascript - electron-store returns "Property 'set''get' does not exist on type&quo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741634106a2389539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论