]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat: merge all properties under this
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 22 Sep 2020 09:41:40 +0000 (11:41 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 22 Sep 2020 09:41:40 +0000 (11:41 +0200)
__tests__/pinia/stores/cart.ts
__tests__/pinia/stores/user.ts
__tests__/state.spec.ts
old test ssr/app/App.ts
package.json
src/store.ts
test-dts/store.test-d.ts
test-dts/tsconfig.json [new file with mode: 0644]
tsconfig.json

index e09307f2abc04fafe47714a660f74d6e7a0f4135..798271f93ad18d76d06d2aad8cfa386a5543dd85 100644 (file)
@@ -7,8 +7,8 @@ export const useCartStore = createStore({
     rawItems: [] as string[],
   }),
   getters: {
-    items: state =>
-      state.rawItems.reduce((items, item) => {
+    items() {
+      return this.rawItems.reduce((items, item) => {
         const existingItem = items.find(it => it.name === item)
 
         if (!existingItem) {
@@ -18,7 +18,8 @@ export const useCartStore = createStore({
         }
 
         return items
-      }, [] as { name: string; amount: number }[]),
+      }, [] as { name: string; amount: number }[])
+    },
   },
 })
 
@@ -40,8 +41,8 @@ export async function purchaseItems() {
   const user = useUserStore()
   if (!user.state.name) return
 
-  console.log('Purchasing', cart.items.value)
-  const n = cart.items.value.length
+  console.log('Purchasing', cart.items)
+  const n = cart.items.length
   cart.state.rawItems = []
 
   return n
index a7c3dfdfa12e171f57fa0b42c1f21efca0c0b20a..52f9a1f30f39d12a76c7d589a0d8d09128b4d601 100644 (file)
@@ -31,7 +31,9 @@ export const useUserStore = createStore({
     },
   },
   getters: {
-    test: state => state.name.toUpperCase(),
+    test() {
+      return this.name.toUpperCase()
+    },
   },
 })
 
index 0737ac96f3124c21d6f73a0b6a5a4905a575001b..7b6599c9d52a6a0dc113e37a02a97347bd1cc653 100644 (file)
@@ -1,5 +1,5 @@
 import { createStore, setActiveReq } from '../src'
-import { computed } from '@vue/composition-api'
+import { computed } from 'vue'
 
 describe('State', () => {
   const useStore = () => {
index dd848fdccfd86d5b2aa1a21e8748597c9843db0d..7900fe7be0da433334c9939cabb05efca10267fb 100644 (file)
@@ -1,7 +1,7 @@
-import { createComponent, computed } from '@vue/composition-api'
+import { defineComponent, computed } from 'vue'
 import { useStore } from './store'
 
-export default createComponent({
+export default defineComponent({
   setup() {
     const store = useStore()
 
index 1f315cc7cc2a8c67c128ee969d5c73fa36715b9e..410ac8238a9aa9f00ab32e13031d5516ffabe362 100644 (file)
@@ -20,6 +20,7 @@
     "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
     "lint": "prettier -c --parser typescript \"{src,__tests__,e2e}/**/*.[jt]s?(x)\"",
     "lint:fix": "yarn run lint --write",
+    "test:dts": "tsc -p ./test-dts/tsconfig.json",
     "test:types": "tsc --build tsconfig.json",
     "test:unit": "jest --coverage",
     "dev": "yarn run unit --watchAll",
index d87b4d185ba3cbdc139ec8805d735bda95f2fc09..554f3bac1835709b33961f92c55e41e80ccfb1fc 100644 (file)
@@ -174,7 +174,7 @@ export function buildStore<
 
 /**
  * Creates a `useStore` function that retrieves the store instance
- * @param options
+ * @param options - options to define the store
  */
 export function createStore<
   Id extends string,
index 831304a44bfc04399ba28b73f312ab697469cef6..943e8c03c3953827bc5343b64b32248e54e47f51 100644 (file)
@@ -4,17 +4,21 @@ const useStore = createStore({
   id: 'name',
   state: () => ({ a: 'on' as 'on' | 'off', nested: { counter: 0 } }),
   getters: {
-    upper: state => state.a.toUpperCase(),
+    upper() {
+      return this.a.toUpperCase()
+    },
   },
 })
 
 const store = useStore()
 
+// FIXME: this should not be there anymore
 expectType<{ a: 'on' | 'off' }>(store.state)
-// expectType<number>(store.nested.counter)
+expectType<number>(store.nested.counter)
+expectType<'on' | 'off'>(store.a)
 
-// not yet @ts-expect-error
-// store.nonExistant
+// @ts-expect-error
+store.nonExistant
 
 // @ts-expect-error
 store.nonExistant.stuff
diff --git a/test-dts/tsconfig.json b/test-dts/tsconfig.json
new file mode 100644 (file)
index 0000000..1a6da39
--- /dev/null
@@ -0,0 +1,13 @@
+{
+  "extends": "../tsconfig.json",
+  "compilerOptions": {
+    "noEmit": true,
+    "declaration": true,
+    "paths": {
+      "vue-router": ["../dist"]
+    },
+    "noImplicitReturns": false
+  },
+  "include": ["./"],
+  "exclude": ["../__tests__", "../src"]
+}
index 50fbf85f8a6b5a5c2768717faf07c3ae76836c6e..b51241d580c9acc7c46e1c5f218e5f15deb34e47 100644 (file)
@@ -16,7 +16,7 @@
     "strictNullChecks": true,
     "noImplicitAny": true,
     "noImplicitThis": true,
-    "noImplicitReturns": true,
+    "noImplicitReturns": false,
     "strict": true,
     "isolatedModules": false,