Skip to content
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

ElectronStore type does not export get, set, or delete #276

Open
raphaelmenges opened this issue May 3, 2024 · 13 comments
Open

ElectronStore type does not export get, set, or delete #276

raphaelmenges opened this issue May 3, 2024 · 13 comments

Comments

@raphaelmenges
Copy link

raphaelmenges commented May 3, 2024

Hi 👋,

I have upgraded the electron-store from 8.2.0 to 9.0.0. Thanks for moving to ESM!

Suddenly, Typescript complains that the methods get, set, or delete are not available for ElectronStore. I looked up the type definition and the methods are neither defined in 8.2.0 nor in 9.0.0. I am not sure why my typecheck did not complain before.

error TS2339: Property 'set' does not exist on type 'ElectronStore<any>'

Perhaps I am missing something in migrating from 8.2.0 to 9.0.0?

@sindresorhus
Copy link
Owner

Make sure you have the correct tsconfig.

@sindresorhus
Copy link
Owner

I looked up the type definition and the methods are neither defined in 8.2.0 nor in 9.0.0. I am not sure why my typecheck did not complain before.

The methods are inherited from Conf.

@raphaelmenges
Copy link
Author

raphaelmenges commented May 5, 2024

I have checked the electron-store module inside my node_modules directory. The type-fest dependency is contained within the electron-store module and the type definitions are found. The conf module however is installed on the same level as the electron-store module. I assume the conf module is required by multiple of my dependencies (perhaps one of your other nice modules!) and npm decided to install it on that level. I have not listed the conf in my package.json. When I change the path in the index.d.ts to conf of the electron-store module as follows, the type check in index.d.ts is fixed but the type check problem in my project persists:

import {type Except} from 'type-fest';
import Conf, {type Options as ConfigOptions} from '../conf/dist/source/types';

export {Schema} from '../conf/dist/source/types';

I am using over 1k (sub-)dependencies in the Electron project that just work fine how I setup the ESM environment, including native modules. Thus, I assume something with electron-store or conf might be broken. Perhaps you have an idea, otherwise I will try to make a minimal project that reproduces the issue!

@tahafatih
Copy link

same problem

@s0hanian
Copy link

s0hanian commented May 7, 2024

I also have the same problem.

@Sam-Spencer
Copy link

I'm also having the same problem, and would also like to reiterate @raphaelmenges comment:

I am using over 1k (sub-)dependencies in the Electron project that just work fine how I setup the ESM environment, including native modules. Thus, I assume something with electron-store or conf might be broken.

@frontierFlight
Copy link

frontierFlight commented May 10, 2024

After using the latest version, I also encountered the same problem and had to use Anyscript!

@sindresorhus
Copy link
Owner

Can you confirm you have "type": "module" in your package.json and "module": "node16", "moduleResolution": "node16" in your tsconfig?


I tried adding this to an existing TypeScript project and it compiles fine for me (npm run build): sindresorhus/got@40026f1

@raphaelmenges
Copy link
Author

raphaelmenges commented May 12, 2024

Can you confirm you have "type": "module" in your package.json and "module": "node16", "moduleResolution": "node16" in your tsconfig?

I have "type": "module" in my package.json and "module": "esnext", "target": "esnext", "moduleResolution": "node" in my tsconfig. When changing the latter to "module": "node16", "moduleResolution": "node16", my own code does no more compile via Typescript due to problems with path resolving. I am using the following (popular?) template: https://github.com/cawa-93/vite-electron-builder/tree/main

PS: Using the mentioned template, I could reproduce the error in a minimal fashion: https://github.com/raphaelmenges/electron-store-type-error

@sindresorhus
Copy link
Owner

sindresorhus commented May 12, 2024

TypeScript does not treat your project as fully ESM unless you have moduleResolution set to either node16 or nodenext.

@sindresorhus
Copy link
Owner

I am using the following (popular?) template: cawa-93/vite-electron-builder@main

Then I suggest opening an issue there. That config is incorrect.

@hywax
Copy link

hywax commented May 13, 2024

@sindresorhus hi, I added code that solves this error, please have a look at it sindresorhus/conf#193

@sindresorhus
Copy link
Owner

Locking this as it seems clear the culprit is incorrect tsconfig.

Here is an example of a correct tsconfig: https://github.com/sindresorhus/tsconfig/blob/main/tsconfig.json

Repository owner locked as resolved and limited conversation to collaborators May 13, 2024
fengyinchao pushed a commit to fengyinchao/electron-store that referenced this issue Aug 8, 2024
codeofandrin added a commit to codeofandrin/electron-store that referenced this issue Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants