Skip to content

Commit

Permalink
refactor: prefer interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jun 16, 2022
1 parent 101ae95 commit b254836
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 4 additions & 2 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const { useSyncExternalStore } = useSyncExternalStoreExports
// type Snapshot<T extends object> = ReturnType<SnapshotWrapper<T>['fn']>
//
// Using copy-paste types for now:
type AsRef = { $$valtioRef: true }
interface AsRef {
$$valtioRef: true
}
type AnyFunction = (...args: any[]) => any
type Snapshot<T> = T extends AnyFunction
? T
Expand All @@ -47,7 +49,7 @@ const useAffectedDebugValue = (
useDebugValue(pathList.current)
}

type Options = {
interface Options {
sync?: boolean
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getVersion, proxy, subscribe } from '../vanilla'

type DeriveGet = <T extends object>(proxyObject: T) => T

type Subscription = {
interface Subscription {
s: object // "s"ourceObject
d: object // "d"erivedObject
k: string // derived "k"ey
Expand Down Expand Up @@ -198,7 +198,7 @@ export function derive<T extends object, U extends object>(
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
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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
}

const DEVTOOLS = Symbol()

type Options = {
interface Options {
enabled?: boolean
name?: string
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/proxyWithComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { proxy, snapshot } from '../vanilla'
// type Snapshot<T extends object> = ReturnType<SnapshotWrapper<T>['fn']>
//
// Using copy-paste types for now:
type AsRef = { $$valtioRef: true }
interface AsRef {
$$valtioRef: true
}
type AnyFunction = (...args: any[]) => any
type Snapshot<T> = T extends AnyFunction
? T
Expand Down
2 changes: 1 addition & 1 deletion src/utils/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { subscribe } from '../vanilla'
type Cleanup = () => void
type WatchGet = <T extends object>(proxyObject: T) => T
type WatchCallback = (get: WatchGet) => Cleanup | void | undefined
type WatchOptions = {
interface WatchOptions {
sync?: boolean
}

Expand Down
4 changes: 3 additions & 1 deletion src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends object>(o: T): T & AsRef {
refSet.add(o)
Expand Down
2 changes: 1 addition & 1 deletion tests/derive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe('glitch free', () => {
})

describe('two derived properties', () => {
type State = {
interface State {
a: number
derived1?: unknown
derived2?: unknown
Expand Down

0 comments on commit b254836

Please sign in to comment.