File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,8 @@ import {
27
27
ModelClone ,
28
28
Id ,
29
29
FeathersVuexStoreState ,
30
- FeathersVuexGlobalModels
30
+ FeathersVuexGlobalModels ,
31
+ FeathersVuexTypeOptions
31
32
} from './service-module/types'
32
33
import { initAuth , hydrateApi } from './utils'
33
34
import { FeathersVuex } from './vue-plugin/vue-plugin'
@@ -119,5 +120,6 @@ export {
119
120
ModelSetupContext ,
120
121
ServiceState ,
121
122
FeathersVuexGlobalModels ,
122
- FeathersVuexStoreState
123
+ FeathersVuexStoreState ,
124
+ FeathersVuexTypeOptions
123
125
}
Original file line number Diff line number Diff line change @@ -112,10 +112,26 @@ export interface ModelInstanceOptions {
112
112
113
113
type AnyData = { [ k : string ] : any }
114
114
115
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
116
+ export interface FeathersVuexTypeOptions {
117
+ // 'model-readonly': true
118
+ }
119
+
120
+ type GetOption < T , K , Default = false > = K extends keyof T ? T [ K ] : Default
121
+
122
+ // ModelData is readonly unless user explicitly says `model-readonly` is false
123
+ type ModelData < D > = GetOption <
124
+ FeathersVuexTypeOptions ,
125
+ 'model-readonly' ,
126
+ true
127
+ > extends false
128
+ ? D
129
+ : Readonly < D >
130
+
115
131
/**
116
132
* FeathersVuex Model with readonly data props
117
133
*/
118
- export type Model < D extends { } = AnyData > = ModelInstance < D > & Readonly < D >
134
+ export type Model < D extends { } = AnyData > = ModelInstance < D > & ModelData < D >
119
135
120
136
/**
121
137
* FeathersVuex Model clone with writeable data props
You can’t perform that action at this time.
0 commit comments