]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: better types
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 11:46:48 +0000 (13:46 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 11:46:48 +0000 (13:46 +0200)
__tests__/mapHelpers.spec.ts
__tests__/ssr/app.spec.ts
__tests__/ssr/app/entry-server.ts
__tests__/ssr/app/main.ts
nuxt/plugin.js
size-checks/small.js
src/mapHelpers.ts
src/store.ts

index 721e29c2a91940db9181998ca3563baf2bbbcb7a..c95a225981ad616528f37c3f39cc4aeb7a064583 100644 (file)
@@ -78,7 +78,7 @@ describe('Map Helpers', () => {
     it('mapStores computes only once when mapping multiple stores', async () => {
       const pinia = createPinia()
       const fromStore = jest.fn(function () {
-        // @ts-ignore
+        // @ts-expect-error
         return this.mainStore
       })
       const Component = defineComponent({
@@ -274,9 +274,9 @@ describe('Map Helpers', () => {
           ...computedProperties,
         },
         methods: Object.keys(computedProperties).reduce((methods, name) => {
-          // @ts-ignore
+          // @ts-expect-error
           methods['set_' + name] = function (v: any) {
-            // @ts-ignore
+            // @ts-expect-error
             this[name] = v
           }
           return methods
@@ -288,7 +288,7 @@ describe('Map Helpers', () => {
       expect(wrapper.text()).toBe(expectedText)
 
       for (const key in computedProperties) {
-        // @ts-ignore
+        // @ts-expect-error
         wrapper.vm['set_' + key]('replaced')
       }
 
index 147bce3b9693d1b1e7f5073043878b8c15a097d0..9080ee37961e4e9ab171dbc7ca97bc9e80526b8c 100644 (file)
@@ -19,7 +19,6 @@ describe('classic vue app', () => {
     const context = createContext()
     const app = await renderApp(context)
 
-    // @ts-ignore
     const html = await renderer.renderToString(app, context)
     expect(html).toMatchInlineSnapshot(
       `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
@@ -30,7 +29,6 @@ describe('classic vue app', () => {
     let context = createContext()
     let app = await renderApp(context)
 
-    // @ts-ignore
     let html = await renderer.renderToString(app, context)
     expect(html).toMatchInlineSnapshot(
       `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
@@ -40,7 +38,6 @@ describe('classic vue app', () => {
     context = createContext()
     app = await renderApp(context)
 
-    // @ts-ignore
     html = await renderer.renderToString(app, context)
     expect(html).toMatchInlineSnapshot(
       `"<div data-server-rendered=\\"true\\"><h2>Hi anon</h2> <p>Count: 1 x 2 = 2</p> <button>Increment</button></div>"`
index 20956047a04572f3f7fb7e8372073f6b8102cb61..e0fd13d0c5c69009ae7911ee83ef69f483731c48 100644 (file)
@@ -1,7 +1,7 @@
 import { createApp } from './main'
 
 export default function (context: any) {
-  return new Promise((resolve) => {
+  return new Promise<ReturnType<typeof createApp>['app']>((resolve) => {
     const { app, pinia } = createApp()
 
     // This `rendered` hook is called when the app has finished rendering
index ce98fcdb807aa9703a39c354dfb4acb9f91a4978..38582717fdb2b94d14e5d7663b88e4be7b5719c2 100644 (file)
@@ -11,7 +11,6 @@ export function createApp() {
   const pinia = createPinia()
   Vue.use(PiniaPlugin)
   const app = new Vue({
-    // @ts-ignore
     pinia,
     render: (h) => h(App),
   })
index 3b7a954ae9dc2d4f2ca075fa6980694cf7ec024a..4f96e787d480e719948d994aafa5ed807a62c52b 100644 (file)
@@ -1,7 +1,7 @@
 // @ts-check
 /// <reference types="./types" />
 import Vue from 'vue'
-// @ts-ignore: this must be pinia to load the local module
+// @ts-expect-error: this must be pinia to load the local module
 import { setActivePinia, PiniaPlugin, createPinia } from 'pinia'
 
 Vue.use(PiniaPlugin)
@@ -20,7 +20,7 @@ const myPlugin = (context, inject) => {
   setActivePinia(pinia)
 
   // we bypass warnings
-  // @ts-ignore
+  // @ts-expect-error
   pinia._p.push(() => ({ $nuxt: context }))
 
   if (process.server) {
index db713e9403684908f63952206dd96be991e9f0eb..b1e6ed8408e5e79930ceb8a5dceb3a2a109d50aa 100644 (file)
@@ -8,5 +8,5 @@ import {
 PiniaPlugin()
 
 createPinia()
-// @ts-ignore
+// @ts-expect-error
 export default defineStore()
index df231757f657351b129f036023a0b906a5a7c605..ee179a0df1fa0935d63609aff0e0178df6796a8c 100644 (file)
@@ -123,7 +123,7 @@ export function mapStores<Stores extends any[]>(
   }
 
   return stores.reduce((reduced, useStore) => {
-    // @ts-ignore: $id is added by defineStore
+    // @ts-expect-error: $id is added by defineStore
     reduced[useStore.$id + mapStoreSuffix] = function (this: Vue) {
       return getCachedStore(this, useStore)
     }
@@ -485,7 +485,6 @@ export function mapWritableState<
 ): _MapWritableStateReturn<S> | _MapWritableStateObjectReturn<S, KeyMapper> {
   return Array.isArray(keysOrMapper)
     ? keysOrMapper.reduce((reduced, key) => {
-        // @ts-ignore
         reduced[key] = {
           get(this: ComponentPublicInstance) {
             return getCachedStore(this, useStore)[key]
@@ -498,7 +497,6 @@ export function mapWritableState<
         return reduced
       }, {} as _MapWritableStateReturn<S>)
     : Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
-        // @ts-ignore
         reduced[key] = {
           get(this: ComponentPublicInstance) {
             return getCachedStore(this, useStore)[keysOrMapper[key]]
index 3b9672780fee5364ff67e60805ebce6721e156ed..69fcdb55303c3c2415c066d4876eff1e614da3e4 100644 (file)
@@ -53,7 +53,7 @@ function innerPatch<T extends StateTree>(
     if (isPlainObject(targetValue) && isPlainObject(subPatch)) {
       target[key] = innerPatch(targetValue, subPatch)
     } else {
-      // @ts-ignore
+      // @ts-expect-error
       target[key] = subPatch
     }
   }
@@ -77,7 +77,7 @@ function computedFromState<T, Id extends string>(
   }
   const state = rootStateRef.value[id]
   for (const key in state) {
-    // @ts-ignore: the key matches
+    // @ts-expect-error: the key matches
     reactiveObject[key] = computed({
       get: () => rootStateRef.value[id][key as keyof T],
       set: (value) => (rootStateRef.value[id][key as keyof T] = value),