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(types): prefer interfaces #474

Merged
merged 1 commit into from
Jun 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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