Skip to content

Commit

Permalink
Upgrade conf
Browse files Browse the repository at this point in the history
Fixes #103
Closes #130
  • Loading branch information
sindresorhus committed Jul 17, 2020
1 parent 2d4a599 commit b29a67e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
12 changes: 4 additions & 8 deletions index.d.ts
@@ -1,15 +1,11 @@
/// <reference types="node"/>
import EventEmitter = require('events');
import {Except} from 'type-fest';
import Conf = require('conf');
import Conf, {Schema as ConfSchema, Options as ConfOptions} from 'conf';

declare namespace ElectronStore {
type Schema = Conf.Schema;
type Schema<T> = ConfSchema<T>;

type Options<T> = Except<
Conf.Options<T>,
'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'
> & {
type Options<T> = Except<ConfOptions<T>, 'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'> & {
/**
Name of the storage file (without extension).
Expand All @@ -24,7 +20,7 @@ declare namespace ElectronStore {
/**
Simple data persistence for your [Electron](https://electronjs.org) app or module - Save and load user preferences, app state, cache, etc.
*/
declare class ElectronStore<T = any> extends Conf<T> {
declare class ElectronStore<T extends Record<string, any> = Record<string, unknown>> extends Conf<T> {
/**
Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing store.
Expand Down
22 changes: 12 additions & 10 deletions index.test-d.ts
@@ -1,8 +1,8 @@
import {expectType} from 'tsd';
import {expectType, expectAssignable} from 'tsd';
import Store = require('.');

new Store({defaults: {}});
new Store({name: 'myConfiguration'});
new Store({defaults: {}}); // eslint-disable-line no-new
new Store({name: 'myConfiguration'}); // eslint-disable-line no-new

const store = new Store();

Expand All @@ -20,20 +20,20 @@ store.clear();

store.openInEditor();

store.size;
store.store;
store.size; // eslint-disable-line @typescript-eslint/no-unused-expressions
store.store; // eslint-disable-line @typescript-eslint/no-unused-expressions

store.store = {
foo: 'bar'
};

store.path;
store.path; // eslint-disable-line @typescript-eslint/no-unused-expressions

type Schema = Store.Schema;
type Schema<T> = Store.Schema<T>;

type TypedStore = {
isEnabled: boolean,
interval: number
isEnabled: boolean;
interval: number;
};

const typedStore = new Store<TypedStore>({
Expand All @@ -43,7 +43,9 @@ const typedStore = new Store<TypedStore>({
}
});

// TODO: This should not be `| undefined`.
expectType<number>(typedStore.get('interval'));

const isEnabled = false;
typedStore.set('isEnabled', isEnabled);
typedStore.set({
Expand All @@ -59,5 +61,5 @@ const offDidChange = typedStore.onDidChange(
}
);

expectType<() => void>(offDidChange);
expectAssignable<() => void>(offDidChange);
offDidChange();
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -34,15 +34,15 @@
"save"
],
"dependencies": {
"conf": "^6.2.1",
"type-fest": "^0.7.1"
"conf": "^7.1.1",
"type-fest": "^0.16.0"
},
"devDependencies": {
"ava": "^2.1.0",
"electron": "^6.0.7",
"execa": "^2.0.4",
"tsd": "^0.11.0",
"xo": "^0.24.0"
"electron": "^9.1.0",
"execa": "^4.0.3",
"tsd": "^0.13.1",
"xo": "^0.32.1"
},
"xo": {
"envs": [
Expand Down

0 comments on commit b29a67e

Please sign in to comment.