Skip to content

Commit

Permalink
Use consistent typing imports (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jun 29, 2022
1 parent 118e881 commit 3013269
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 42 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/consistent-type-imports": [2, {"prefer": "type-imports"}],
"@typescript-eslint/ban-types": 0,
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 1,
Expand Down
4 changes: 2 additions & 2 deletions _internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as revalidateEvents from './constants'
import { defaultConfig } from './utils/config'
import type * as revalidateEvents from './constants'
import type { defaultConfig } from './utils/config'

export type GlobalState = [
Record<string, RevalidateCallback[]>, // EVENT_REVALIDATORS
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { internalMutate } from './mutate'
import { SWRGlobalState } from './global-state'
import * as revalidateEvents from '../constants'

import {
import type {
Cache,
ScopedMutator,
RevalidateEvent,
Expand Down
12 changes: 3 additions & 9 deletions _internal/utils/config-context.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {
createContext,
createElement,
useContext,
useState,
FC,
PropsWithChildren
} from 'react'
import type { FC, PropsWithChildren } from 'react'
import { createContext, createElement, useContext, useState } from 'react'
import { cache as defaultCache } from './config'
import { initCache } from './cache'
import { mergeConfigs } from './merge-config'
import { UNDEFINED, mergeObjects, isFunction } from './helper'
import { useIsomorphicLayoutEffect } from './env'
import {
import type {
SWRConfiguration,
FullConfiguration,
ProviderConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/global-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cache, GlobalState } from '../types'
import type { Cache, GlobalState } from '../types'

// Global state used to deduplicate requests and store listeners
export const SWRGlobalState = new WeakMap<Cache, GlobalState>()
2 changes: 1 addition & 1 deletion _internal/utils/merge-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeObjects } from './helper'
import { FullConfiguration } from '../types'
import type { FullConfiguration } from '../types'

export const mergeConfigs = (
a: Partial<FullConfiguration>,
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createCacheHelper, isFunction, isUndefined, UNDEFINED } from './helper'
import { SWRGlobalState } from './global-state'
import { getTimestamp } from './timestamp'
import * as revalidateEvents from '../constants'
import {
import type {
Cache,
MutatorCallback,
MutatorOptions,
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/normalize-args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFunction } from './helper'

import { Key, Fetcher, SWRConfiguration } from '../types'
import type { Key, Fetcher, SWRConfiguration } from '../types'

export const normalize = <KeyType = Key, Data = any>(
args:
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stableHash } from './hash'
import { isFunction } from './helper'

import { Key } from '../types'
import type { Key } from '../types'

export const serialize = (key: Key): [string, Key] => {
if (isFunction(key)) {
Expand Down
3 changes: 2 additions & 1 deletion _internal/utils/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useRef, useCallback, useState, MutableRefObject } from 'react'
import type { MutableRefObject } from 'react'
import React, { useRef, useCallback, useState } from 'react'

import { useIsomorphicLayoutEffect, IS_REACT_LEGACY } from './env'

Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/use-swr-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useContext } from 'react'
import { defaultConfig } from './config'
import { SWRConfigContext } from './config-context'
import { mergeObjects } from './helper'
import { FullConfiguration, Cache, State } from '../types'
import type { FullConfiguration, Cache, State } from '../types'

export const useSWRConfig = <
T extends Cache = Map<string, State>
Expand Down
2 changes: 1 addition & 1 deletion _internal/utils/web-preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProviderConfiguration } from '../types'
import type { ProviderConfiguration } from '../types'
import { isUndefined, noop, isWindowDefined, isDocumentDefined } from './helper'

/**
Expand Down
8 changes: 7 additions & 1 deletion _internal/utils/with-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { normalize } from './normalize-args'

import { Key, Fetcher, Middleware, SWRConfiguration, SWRHook } from '../types'
import type {
Key,
Fetcher,
Middleware,
SWRConfiguration,
SWRHook
} from '../types'

// Create a custom hook with a middleware
export const withMiddleware = (
Expand Down
4 changes: 2 additions & 2 deletions core/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
rAF,
useIsomorphicLayoutEffect,
SWRGlobalState,
GlobalState,
serialize,
isUndefined,
UNDEFINED,
Expand All @@ -33,7 +32,8 @@ import type {
SWRConfiguration,
SWRHook,
RevalidateEvent,
StateDependencies
StateDependencies,
GlobalState
} from 'swr/_internal'

const WITH_DEDUPE = { dedupe: true }
Expand Down
3 changes: 2 additions & 1 deletion infinite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// hook where `key` and return type are not like the normal `useSWR` types.

import { useRef, useCallback } from 'react'
import useSWR, { SWRConfig } from 'swr'
import type { SWRConfig } from 'swr'
import useSWR from 'swr'
import {
isUndefined,
isFunction,
Expand Down
2 changes: 1 addition & 1 deletion infinite/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
SWRConfiguration,
SWRResponse,
Arguments,
Expand Down
5 changes: 2 additions & 3 deletions mutation/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useCallback, useRef } from 'react'
import useSWR, { useSWRConfig } from 'swr'
import type { Middleware, Key } from 'swr/_internal'
import {
serialize,
useStateWithDeps,
withMiddleware,
useIsomorphicLayoutEffect,
UNDEFINED,
getTimestamp,
Middleware,
Key
getTimestamp
} from 'swr/_internal'
import type {
SWRMutationConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion mutation/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SWRResponse, Key, MutatorOptions } from 'swr'
import type { SWRResponse, Key, MutatorOptions } from 'swr'

type FetcherResponse<Data> = Data | Promise<Data>

Expand Down
3 changes: 2 additions & 1 deletion test/type/config.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { useSWRConfig, SWRConfig, Cache, State } from 'swr'
import type { Cache, State } from 'swr'
import { useSWRConfig, SWRConfig } from 'swr'
import { expectType } from './utils'

interface CustomCache<Data = any> extends Cache<Data> {
Expand Down
4 changes: 2 additions & 2 deletions test/type/mutator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Equal, Expect } from '@type-challenges/utils'
import type { Equal, Expect } from '@type-challenges/utils'
import useSWR, { useSWRConfig } from 'swr'

import {
import type {
MutatorFn,
Key,
MutatorCallback,
Expand Down
3 changes: 2 additions & 1 deletion test/use-swr-config.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { act, screen, fireEvent } from '@testing-library/react'
import React, { useEffect, useState } from 'react'
import useSWR, { SWRConfig, useSWRConfig, Middleware } from 'swr'
import type { Middleware } from 'swr'
import useSWR, { SWRConfig, useSWRConfig } from 'swr'
import { renderWithConfig, createKey, renderWithGlobalCache } from './utils'

describe('useSWR - configs', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/use-swr-middlewares.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { act, screen } from '@testing-library/react'
import React, { useState, useEffect, useRef } from 'react'
import useSWR, { Middleware, SWRConfig } from 'swr'
import type { Middleware } from 'swr'
import useSWR, { SWRConfig } from 'swr'
import { withMiddleware } from '../_internal/utils/with-middleware'

import {
Expand Down
10 changes: 2 additions & 8 deletions test/use-swr-suspense.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { act, fireEvent, screen } from '@testing-library/react'
import React, {
ReactNode,
Suspense,
useEffect,
useReducer,
useState,
PropsWithChildren
} from 'react'
import type { ReactNode, PropsWithChildren } from 'react'
import React, { Suspense, useEffect, useReducer, useState } from 'react'
import useSWR, { mutate } from 'swr'
import {
createKey,
Expand Down

0 comments on commit 3013269

Please sign in to comment.