]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat: mark getters as readonly
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 29 Apr 2021 12:45:02 +0000 (14:45 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 29 Apr 2021 12:45:02 +0000 (14:45 +0200)
src/store.ts
src/types.ts
test-dts/store.test-d.ts

index cfe8a3c75abe98086a745da8616dc3961455a9b1..fe96a9242e23526f0eb6a83b861f2805151f9af5 100644 (file)
@@ -229,6 +229,7 @@ function buildStoreToUse<
 
   const computedGetters: StoreWithGetters<G> = {} as StoreWithGetters<G>
   for (const getterName in getters) {
+    // @ts-ignore: it's only readonly for the users
     computedGetters[getterName] = computed(() => {
       setActivePinia(pinia)
       // eslint-disable-next-line @typescript-eslint/no-use-before-define
index ee3102106d79414be48aabf9ad5be8ff4290e804..bd1ed9adc9de23d7a7045c148c1aff3b28369faa 100644 (file)
@@ -122,7 +122,10 @@ export type StoreWithActions<A> = {
  * @internal
  */
 export type StoreWithGetters<G> = {
-  [k in keyof G]: G[k] extends (this: infer This, store?: any) => infer R
+  readonly [k in keyof G]: G[k] extends (
+    this: infer This,
+    store?: any
+  ) => infer R
     ? R
     : never
 }
index e1a02adfd0123d3180d50a38fe7bee6cd6cc1fb4..fcb4bee32f51ad6e8618849e65ad24fe90349174 100644 (file)
@@ -33,6 +33,9 @@ expectType<'on' | 'off'>(store.a)
 // @ts-expect-error
 store.nonExistant
 
+// @ts-expect-error
+store.upper = 'thing'
+
 // @ts-expect-error
 store.nonExistant.stuff