Skip to content

Commit 6c73938

Browse files
committed
new: if user does not augment Store or GlobalModels, use any
1 parent d3579ed commit 6c73938

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
Id,
2929
FeathersVuexStoreState,
3030
FeathersVuexGlobalModels,
31-
FeathersVuexTypeOptions
31+
FeathersVuexTypeOptions,
32+
GlobalModels
3233
} from './service-module/types'
3334
import { initAuth, hydrateApi } from './utils'
3435
import { FeathersVuex } from './vue-plugin/vue-plugin'
@@ -86,7 +87,7 @@ export default function feathersVuex(feathers, options: FeathersVuexOptions) {
8687
castBaseModel: <T extends {} = {}>() => BaseModel as ModelStatic<T>,
8788
makeAuthPlugin,
8889
FeathersVuex,
89-
models: models as FeathersVuexGlobalModels,
90+
models: models as GlobalModels,
9091
clients
9192
}
9293
}

src/service-module/make-base-model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
ModelStatic,
1212
ModelInstanceClone,
1313
ModelClone,
14-
FeathersVuexGlobalModels,
15-
FeathersVuexStoreState
14+
GlobalModels,
15+
StoreState
1616
} from './types'
1717
import { globalModels, prepareAddModel } from './global-models'
1818
import { mergeWithAccessors, checkNamespace, getId, Params } from '../utils'
@@ -81,14 +81,14 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
8181
}
8282

8383
// Monkey patched onto the Model class in `makeServicePlugin()`
84-
public static store: Store<FeathersVuexStoreState>
84+
public static store: Store<StoreState>
8585

8686
public static idField: string = options.idField
8787
public static tempIdField: string = options.tempIdField
8888
public static preferUpdate: boolean = options.preferUpdate
8989
public static serverAlias: string = options.serverAlias
9090

91-
public static readonly models = globalModels as FeathersVuexGlobalModels // Can access other Models here
91+
public static readonly models = globalModels as GlobalModels // Can access other Models here
9292
public static copiesById: {
9393
[key: string]: ModelClone<D> | undefined
9494
[key: number]: ModelClone<D> | undefined

src/service-module/types.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export interface FeathersVuexGlobalModels {
7474
/** Allow clients to augment Global models */
7575
}
7676

77+
// Alias and default to any if user doesn't augment interfaces
78+
export type StoreState = keyof FeathersVuexStoreState extends never ? any : FeathersVuexStoreState
79+
export type GlobalModels = keyof FeathersVuexGlobalModels extends never ? any : FeathersVuexGlobalModels
80+
7781
interface PatchParams<D> extends Params {
7882
data: Partial<D>
7983
}
@@ -82,11 +86,11 @@ export interface ModelSetupContext {
8286
/**
8387
* The global Vuex store
8488
*/
85-
store: FeathersVuexStoreState
89+
store: StoreState
8690
/**
8791
* The global `models` object
8892
*/
89-
models: FeathersVuexGlobalModels
93+
models: GlobalModels
9094
}
9195

9296
export interface ModelInstanceOptions {
@@ -153,7 +157,7 @@ export interface ModelStatic<D extends {} = AnyData> extends EventEmitter {
153157
/**
154158
* The global Vuex store
155159
*/
156-
readonly store: Store<FeathersVuexStoreState>
160+
readonly store: Store<StoreState>
157161
/**
158162
* The field in each record that will contain the ID
159163
*/
@@ -177,7 +181,7 @@ export interface ModelStatic<D extends {} = AnyData> extends EventEmitter {
177181
/**
178182
* The global `models` object
179183
*/
180-
readonly models: FeathersVuexGlobalModels
184+
readonly models: GlobalModels
181185
/**
182186
* All model copies created using `model.clone()`
183187
*/

src/vue-plugin/vue-plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import FeathersVuexFormWrapper from '../FeathersVuexFormWrapper'
99
import FeathersVuexInputWrapper from '../FeathersVuexInputWrapper'
1010
import FeathersVuexPagination from '../FeathersVuexPagination'
1111
import { globalModels } from '../service-module/global-models'
12-
import { FeathersVuexGlobalModels } from '../service-module/types'
12+
import { GlobalModels } from '../service-module/types'
1313

1414
// Augment global models onto VueConstructor and instance
1515
declare module 'vue/types/vue' {
1616
interface VueConstructor {
17-
$FeathersVuex: FeathersVuexGlobalModels
17+
$FeathersVuex: GlobalModels
1818
}
1919
interface Vue {
20-
$FeathersVuex: FeathersVuexGlobalModels
20+
$FeathersVuex: GlobalModels
2121
}
2222
}
2323

0 commit comments

Comments
 (0)