From: Eduardo San Martin Morote Date: Sat, 15 May 2021 11:46:48 +0000 (+0200) Subject: refactor: better types X-Git-Tag: v0.5.0~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f7b2e8e544fc7144dac76d4702af87eddd071fa2;p=thirdparty%2Fvuejs%2Fpinia.git refactor: better types --- diff --git a/__tests__/mapHelpers.spec.ts b/__tests__/mapHelpers.spec.ts index 721e29c2..c95a2259 100644 --- a/__tests__/mapHelpers.spec.ts +++ b/__tests__/mapHelpers.spec.ts @@ -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') } diff --git a/__tests__/ssr/app.spec.ts b/__tests__/ssr/app.spec.ts index 147bce3b..9080ee37 100644 --- a/__tests__/ssr/app.spec.ts +++ b/__tests__/ssr/app.spec.ts @@ -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( `"

Hi anon

Count: 1 x 2 = 2

"` @@ -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( `"

Hi anon

Count: 1 x 2 = 2

"` @@ -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( `"

Hi anon

Count: 1 x 2 = 2

"` diff --git a/__tests__/ssr/app/entry-server.ts b/__tests__/ssr/app/entry-server.ts index 20956047..e0fd13d0 100644 --- a/__tests__/ssr/app/entry-server.ts +++ b/__tests__/ssr/app/entry-server.ts @@ -1,7 +1,7 @@ import { createApp } from './main' export default function (context: any) { - return new Promise((resolve) => { + return new Promise['app']>((resolve) => { const { app, pinia } = createApp() // This `rendered` hook is called when the app has finished rendering diff --git a/__tests__/ssr/app/main.ts b/__tests__/ssr/app/main.ts index ce98fcdb..38582717 100644 --- a/__tests__/ssr/app/main.ts +++ b/__tests__/ssr/app/main.ts @@ -11,7 +11,6 @@ export function createApp() { const pinia = createPinia() Vue.use(PiniaPlugin) const app = new Vue({ - // @ts-ignore pinia, render: (h) => h(App), }) diff --git a/nuxt/plugin.js b/nuxt/plugin.js index 3b7a954a..4f96e787 100644 --- a/nuxt/plugin.js +++ b/nuxt/plugin.js @@ -1,7 +1,7 @@ // @ts-check /// 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) { diff --git a/size-checks/small.js b/size-checks/small.js index db713e94..b1e6ed84 100644 --- a/size-checks/small.js +++ b/size-checks/small.js @@ -8,5 +8,5 @@ import { PiniaPlugin() createPinia() -// @ts-ignore +// @ts-expect-error export default defineStore() diff --git a/src/mapHelpers.ts b/src/mapHelpers.ts index df231757..ee179a0d 100644 --- a/src/mapHelpers.ts +++ b/src/mapHelpers.ts @@ -123,7 +123,7 @@ export function mapStores( } 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 | _MapWritableStateObjectReturn { 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) : Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => { - // @ts-ignore reduced[key] = { get(this: ComponentPublicInstance) { return getCachedStore(this, useStore)[keysOrMapper[key]] diff --git a/src/store.ts b/src/store.ts index 3b967278..69fcdb55 100644 --- a/src/store.ts +++ b/src/store.ts @@ -53,7 +53,7 @@ function innerPatch( 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( } 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),