Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: stricter tsconfig #678

Merged
merged 3 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/core/store.ts
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/splitAtom.ts
Expand Up @@ -69,7 +69,7 @@ export function splitAtom<Item, Key>(
atom
)
}
return get(arrAtom)[index]
return get(arrAtom)[index] as Item
}
const write = (
get: Getter,
Expand All @@ -81,7 +81,9 @@ export function splitAtom<Item, Key>(
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<Item[], Item[]>, [
...prev.slice(0, index),
nextItem,
Expand Down
4 changes: 1 addition & 3 deletions src/utils/waitForAll.ts
Expand Up @@ -51,9 +51,7 @@ const unwrapAtoms = <
>(atoms: { [K in keyof Values]: Atom<Values[K]> }): Atom<unknown>[] =>
Array.isArray(atoms)
? atoms
: Object.getOwnPropertyNames(atoms).map(
(key) => (atoms as Record<string, Atom<unknown>>)[key]
)
: Object.getOwnPropertyNames(atoms).map((key) => atoms[key as keyof Values])

const wrapResults = <Values extends Record<string, unknown> | unknown[]>(
atoms: { [K in keyof Values]: Atom<Values[K]> },
Expand Down
6 changes: 3 additions & 3 deletions src/utils/weakCache.ts
Expand Up @@ -6,7 +6,7 @@ export const getWeakCacheItem = <T>(
): T | undefined => {
while (true) {
const [dep, ...rest] = deps
const entry = cache.get(dep)
const entry = cache.get(dep as object)
if (!entry) {
return
}
Expand All @@ -25,10 +25,10 @@ export const setWeakCacheItem = <T>(
): 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
Expand Down
14 changes: 8 additions & 6 deletions tests/utils/atomFamily.test.tsx
Expand Up @@ -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<number, number>((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))
Expand All @@ -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<number, number>((num) =>
atom((get) => get(bigAtom)[num])
atom((get) => get(bigAtom)[num] as number)
)

const savedReference = myFamily(0)
Expand Down Expand Up @@ -116,13 +116,15 @@ it('derived atomFamily functionality as usual', async () => {

const myFamily = atomFamily<number, number, SetStateAction<number>>((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),
Expand Down Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/atomWithStorage.test.tsx
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions 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"]
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -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"
Expand Down