From d5eaac106c50be8febc25083839e7cb635ccfda7 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 22 Sep 2020 11:41:40 +0200 Subject: [PATCH] feat: merge all properties under this --- __tests__/pinia/stores/cart.ts | 11 ++++++----- __tests__/pinia/stores/user.ts | 4 +++- __tests__/state.spec.ts | 2 +- old test ssr/app/App.ts | 4 ++-- package.json | 1 + src/store.ts | 2 +- test-dts/store.test-d.ts | 12 ++++++++---- test-dts/tsconfig.json | 13 +++++++++++++ tsconfig.json | 2 +- 9 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 test-dts/tsconfig.json diff --git a/__tests__/pinia/stores/cart.ts b/__tests__/pinia/stores/cart.ts index e09307f2..798271f9 100644 --- a/__tests__/pinia/stores/cart.ts +++ b/__tests__/pinia/stores/cart.ts @@ -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 diff --git a/__tests__/pinia/stores/user.ts b/__tests__/pinia/stores/user.ts index a7c3dfdf..52f9a1f3 100644 --- a/__tests__/pinia/stores/user.ts +++ b/__tests__/pinia/stores/user.ts @@ -31,7 +31,9 @@ export const useUserStore = createStore({ }, }, getters: { - test: state => state.name.toUpperCase(), + test() { + return this.name.toUpperCase() + }, }, }) diff --git a/__tests__/state.spec.ts b/__tests__/state.spec.ts index 0737ac96..7b6599c9 100644 --- a/__tests__/state.spec.ts +++ b/__tests__/state.spec.ts @@ -1,5 +1,5 @@ import { createStore, setActiveReq } from '../src' -import { computed } from '@vue/composition-api' +import { computed } from 'vue' describe('State', () => { const useStore = () => { diff --git a/old test ssr/app/App.ts b/old test ssr/app/App.ts index dd848fdc..7900fe7b 100644 --- a/old test ssr/app/App.ts +++ b/old test ssr/app/App.ts @@ -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() diff --git a/package.json b/package.json index 1f315cc7..410ac823 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/store.ts b/src/store.ts index d87b4d18..554f3bac 100644 --- a/src/store.ts +++ b/src/store.ts @@ -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, diff --git a/test-dts/store.test-d.ts b/test-dts/store.test-d.ts index 831304a4..943e8c03 100644 --- a/test-dts/store.test-d.ts +++ b/test-dts/store.test-d.ts @@ -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(store.nested.counter) +expectType(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 index 00000000..1a6da392 --- /dev/null +++ b/test-dts/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "declaration": true, + "paths": { + "vue-router": ["../dist"] + }, + "noImplicitReturns": false + }, + "include": ["./"], + "exclude": ["../__tests__", "../src"] +} diff --git a/tsconfig.json b/tsconfig.json index 50fbf85f..b51241d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,7 @@ "strictNullChecks": true, "noImplicitAny": true, "noImplicitThis": true, - "noImplicitReturns": true, + "noImplicitReturns": false, "strict": true, "isolatedModules": false, -- 2.47.2