From b254836a284544553222086f59fa0b00b92583a3 Mon Sep 17 00:00:00 2001 From: daishi Date: Thu, 16 Jun 2022 18:15:22 +0900 Subject: [PATCH] refactor: prefer interfaces --- .eslintrc.json | 2 +- src/react.ts | 6 ++++-- src/utils/derive.ts | 4 ++-- src/utils/devtools.ts | 4 ++-- src/utils/proxyWithComputed.ts | 4 +++- src/utils/watch.ts | 2 +- src/vanilla.ts | 4 +++- tests/derive.test.tsx | 2 +- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2239d219..0e299b4d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -46,8 +46,8 @@ ], "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/consistent-type-definitions": ["error", "interface"], "jest/consistent-test-it": [ "error", { "fn": "it", "withinDescribe": "it" } diff --git a/src/react.ts b/src/react.ts index a4be9c60..018259e0 100644 --- a/src/react.ts +++ b/src/react.ts @@ -24,7 +24,9 @@ const { useSyncExternalStore } = useSyncExternalStoreExports // type Snapshot = ReturnType['fn']> // // Using copy-paste types for now: -type AsRef = { $$valtioRef: true } +interface AsRef { + $$valtioRef: true +} type AnyFunction = (...args: any[]) => any type Snapshot = T extends AnyFunction ? T @@ -47,7 +49,7 @@ const useAffectedDebugValue = ( useDebugValue(pathList.current) } -type Options = { +interface Options { sync?: boolean } diff --git a/src/utils/derive.ts b/src/utils/derive.ts index 4a05135a..1f00c22c 100644 --- a/src/utils/derive.ts +++ b/src/utils/derive.ts @@ -2,7 +2,7 @@ import { getVersion, proxy, subscribe } from '../vanilla' type DeriveGet = (proxyObject: T) => T -type Subscription = { +interface Subscription { s: object // "s"ourceObject d: object // "d"erivedObject k: string // derived "k"ey @@ -198,7 +198,7 @@ export function derive( throw new Error('object property already defined') } const fn = derivedFns[key as keyof U] - type DependencyEntry = { + interface DependencyEntry { v: number // "v"ersion s?: Subscription // "s"ubscription } diff --git a/src/utils/devtools.ts b/src/utils/devtools.ts index b50d889d..838c21a1 100644 --- a/src/utils/devtools.ts +++ b/src/utils/devtools.ts @@ -2,7 +2,7 @@ import { snapshot, subscribe } from '../vanilla' import type {} from '@redux-devtools/extension' // FIXME https://github.com/reduxjs/redux-devtools/issues/1097 -type Message = { +interface Message { type: string payload?: any state?: any @@ -10,7 +10,7 @@ type Message = { const DEVTOOLS = Symbol() -type Options = { +interface Options { enabled?: boolean name?: string } diff --git a/src/utils/proxyWithComputed.ts b/src/utils/proxyWithComputed.ts index 5950c474..1e264f06 100644 --- a/src/utils/proxyWithComputed.ts +++ b/src/utils/proxyWithComputed.ts @@ -11,7 +11,9 @@ import { proxy, snapshot } from '../vanilla' // type Snapshot = ReturnType['fn']> // // Using copy-paste types for now: -type AsRef = { $$valtioRef: true } +interface AsRef { + $$valtioRef: true +} type AnyFunction = (...args: any[]) => any type Snapshot = T extends AnyFunction ? T diff --git a/src/utils/watch.ts b/src/utils/watch.ts index 14fbd635..7c3602ab 100644 --- a/src/utils/watch.ts +++ b/src/utils/watch.ts @@ -3,7 +3,7 @@ import { subscribe } from '../vanilla' type Cleanup = () => void type WatchGet = (proxyObject: T) => T type WatchCallback = (get: WatchGet) => Cleanup | void | undefined -type WatchOptions = { +interface WatchOptions { sync?: boolean } diff --git a/src/vanilla.ts b/src/vanilla.ts index 1c752d7e..71255996 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -7,7 +7,9 @@ const HANDLER = __DEV__ ? Symbol('HANDLER') : Symbol() const PROMISE_RESULT = __DEV__ ? Symbol('PROMISE_RESULT') : Symbol() const PROMISE_ERROR = __DEV__ ? Symbol('PROMISE_ERROR') : Symbol() -type AsRef = { $$valtioRef: true } +interface AsRef { + $$valtioRef: true +} const refSet = new WeakSet() export function ref(o: T): T & AsRef { refSet.add(o) diff --git a/tests/derive.test.tsx b/tests/derive.test.tsx index 6cdafd68..174fdd5f 100644 --- a/tests/derive.test.tsx +++ b/tests/derive.test.tsx @@ -411,7 +411,7 @@ describe('glitch free', () => { }) describe('two derived properties', () => { - type State = { + interface State { a: number derived1?: unknown derived2?: unknown