diff --git a/package.json b/package.json index 76fb834807..958718be9e 100644 --- a/package.json +++ b/package.json @@ -218,7 +218,7 @@ "ts-expect": "^1.3.0", "ts-node": "^10.2.1", "tslib": "^2.3.1", - "typescript": "4.3.5", + "typescript": "^4.4.3", "valtio": "^1.1.3", "wonka": "^4.0.15", "xstate": "^4.17.1", diff --git a/src/core/store.ts b/src/core/store.ts index 01f8b4046c..937827cceb 100644 --- a/src/core/store.ts +++ b/src/core/store.ts @@ -310,7 +310,7 @@ export const createStore = ( } else if (errorOrPromise instanceof Error) { error = errorOrPromise } else { - error = new Error(errorOrPromise) + error = new Error(errorOrPromise as string) } } if (error) { diff --git a/src/utils/splitAtom.ts b/src/utils/splitAtom.ts index d05b6e03e8..062e3b90a7 100644 --- a/src/utils/splitAtom.ts +++ b/src/utils/splitAtom.ts @@ -69,7 +69,7 @@ export function splitAtom( atom ) } - return get(arrAtom)[index] + return get(arrAtom)[index] as Item } const write = ( get: Getter, @@ -81,7 +81,9 @@ export function splitAtom( throw new Error('splitAtom: array index not found') } const prev = get(arrAtom) - const nextItem = isFunction(update) ? update(prev[index]) : update + const nextItem = isFunction(update) + ? update(prev[index] as Item) + : update set(arrAtom as WritableAtom, [ ...prev.slice(0, index), nextItem, diff --git a/src/utils/waitForAll.ts b/src/utils/waitForAll.ts index de884b9669..ad0bbb26b8 100644 --- a/src/utils/waitForAll.ts +++ b/src/utils/waitForAll.ts @@ -51,9 +51,7 @@ const unwrapAtoms = < >(atoms: { [K in keyof Values]: Atom }): Atom[] => Array.isArray(atoms) ? atoms - : Object.getOwnPropertyNames(atoms).map( - (key) => (atoms as Record>)[key] - ) + : Object.getOwnPropertyNames(atoms).map((key) => atoms[key as keyof Values]) const wrapResults = | unknown[]>( atoms: { [K in keyof Values]: Atom }, diff --git a/src/utils/weakCache.ts b/src/utils/weakCache.ts index 2404d5d9de..a6fd2c7a8f 100644 --- a/src/utils/weakCache.ts +++ b/src/utils/weakCache.ts @@ -6,7 +6,7 @@ export const getWeakCacheItem = ( ): T | undefined => { while (true) { const [dep, ...rest] = deps - const entry = cache.get(dep) + const entry = cache.get(dep as object) if (!entry) { return } @@ -25,10 +25,10 @@ export const setWeakCacheItem = ( ): void => { while (true) { const [dep, ...rest] = deps - let entry = cache.get(dep) + let entry = cache.get(dep as object) if (!entry) { entry = [new WeakMap()] - cache.set(dep, entry) + cache.set(dep as object, entry) } if (!rest.length) { entry[1] = item diff --git a/tests/utils/atomFamily.test.tsx b/tests/utils/atomFamily.test.tsx index 994091f4f7..3d5ea6f789 100644 --- a/tests/utils/atomFamily.test.tsx +++ b/tests/utils/atomFamily.test.tsx @@ -41,7 +41,7 @@ it('primitive atomFamily returns same reference for same parameters', async () = it('read-only derived atomFamily returns same reference for same parameters', async () => { const arrayAtom = atom([0]) const myFamily = atomFamily((num) => - atom((get) => get(arrayAtom)[num]) + atom((get) => get(arrayAtom)[num] as number) ) expect(myFamily(0)).toEqual(myFamily(0)) expect(myFamily(0)).not.toEqual(myFamily(1)) @@ -51,7 +51,7 @@ it('read-only derived atomFamily returns same reference for same parameters', as it('removed atom creates a new reference', async () => { const bigAtom = atom([0]) const myFamily = atomFamily((num) => - atom((get) => get(bigAtom)[num]) + atom((get) => get(bigAtom)[num] as number) ) const savedReference = myFamily(0) @@ -116,13 +116,15 @@ it('derived atomFamily functionality as usual', async () => { const myFamily = atomFamily>((param) => atom( - (get) => get(arrayAtom)[param], + (get) => get(arrayAtom)[param] as number, (_, set, update) => { set(arrayAtom, (oldArray) => { if (typeof oldArray[param] === 'undefined') return oldArray const newValue = - typeof update === 'function' ? update(oldArray[param]) : update + typeof update === 'function' + ? update(oldArray[param] as number) + : update const newArray = [ ...oldArray.slice(0, param), @@ -206,11 +208,11 @@ it('custom equality function work', async () => { const bigAtom = atom([0]) const badFamily = atomFamily<{ index: number }, number>((num) => - atom((get) => get(bigAtom)[num.index]) + atom((get) => get(bigAtom)[num.index] as number) ) const goodFamily = atomFamily<{ index: number }, number>( - (num) => atom((get) => get(bigAtom)[num.index]), + (num) => atom((get) => get(bigAtom)[num.index] as number), (l, r) => l.index === r.index ) diff --git a/tests/utils/atomWithStorage.test.tsx b/tests/utils/atomWithStorage.test.tsx index 39e142d718..8ebb6c413e 100644 --- a/tests/utils/atomWithStorage.test.tsx +++ b/tests/utils/atomWithStorage.test.tsx @@ -23,7 +23,7 @@ describe('atomWithStorage (sync)', () => { if (!(key in storageData)) { throw new Error('no value stored') } - return storageData[key] + return storageData[key] as number }, setItem: (key: string, newValue: number) => { storageData[key] = newValue @@ -67,7 +67,7 @@ describe('atomWithStorage (async)', () => { if (!(key in asyncStorageData)) { throw new Error('no value stored') } - return asyncStorageData[key] + return asyncStorageData[key] as number }, setItem: async (key: string, newValue: number) => { await new Promise((r) => setTimeout(r, 10)) diff --git a/tsconfig.json b/tsconfig.json index e950ca0bce..94235c5a3b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { - "target": "es2019", + "target": "esnext", "strict": true, "jsx": "react-jsx", - "allowSyntheticDefaultImports": true, "esModuleInterop": true, "moduleResolution": "node", + "noUncheckedIndexedAccess": true, "baseUrl": ".", "paths": { "jotai": ["./src/index.ts"] diff --git a/yarn.lock b/yarn.lock index 1f70e64f41..ddd96ec07a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7114,16 +7114,16 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== - typescript@^4.1.0-dev.20201026: version "4.4.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== +typescript@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" + integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== + unbox-primitive@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"