Skip to content

Commit 7d36089

Browse files
kangju2000manudelisaul-atomrigsTkDodo
authored
refactor(*): change noop function return type from undefined to void (#8299)
* refactor(*): use noop * refactor: separate noop and returnUndefined functions with type refinement Co-authored-by: Jonghyeon Ko <[email protected]> Co-authored-by: Sol Lee <[email protected]> * refactor: optimize bundle size with type re-assertion * fix: Prevent type error by overloading noop function * fix: remove jsdoc * fix * revert * revert at react-query and angular-query-experimental --------- Co-authored-by: Jonghyeon Ko <[email protected]> Co-authored-by: Sol Lee <[email protected]> Co-authored-by: Dominik Dorfmeister <[email protected]>
1 parent fadfbde commit 7d36089

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

packages/angular-query-experimental/src/providers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { QueryClient, onlineManager } from '@tanstack/query-core'
1313
import { isPlatformBrowser } from '@angular/common'
1414
import { isDevMode } from './util/is-dev-mode/is-dev-mode'
15+
import { noop } from './util'
1516
import type { EnvironmentProviders, Provider } from '@angular/core'
1617
import type {
1718
DevtoolsButtonPosition,
@@ -251,7 +252,7 @@ export function withDevtools(
251252
provide: ENVIRONMENT_INITIALIZER,
252253
multi: true,
253254
useFactory: () => {
254-
if (!isPlatformBrowser(inject(PLATFORM_ID))) return () => {}
255+
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop
255256
const injector = inject(Injector)
256257
const options = computed(() =>
257258
runInInjectionContext(injector, () => optionsFn?.() ?? {}),
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export function noop(): void {}
1+
export function noop(): void
2+
export function noop(): undefined
3+
export function noop() {}

packages/query-core/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export type QueryTypeFilter = 'all' | 'active' | 'inactive'
6868

6969
export const isServer = typeof window === 'undefined' || 'Deno' in globalThis
7070

71-
export function noop(): undefined {
72-
return undefined
73-
}
71+
export function noop(): void
72+
export function noop(): undefined
73+
export function noop() {}
7474

7575
export function functionalUpdate<TInput, TOutput>(
7676
updater: Updater<TInput, TOutput>,

packages/query-sync-storage-persister/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function createSyncStoragePersister({
8888

8989
return {
9090
persistClient: noop,
91-
restoreClient: () => undefined,
91+
restoreClient: noop,
9292
removeClient: noop,
9393
}
9494
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export function noop(): void {}
1+
export function noop(): void
2+
export function noop(): undefined
3+
export function noop() {}

packages/svelte-query/src/createBaseQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { derived, get, readable } from 'svelte/store'
22
import { notifyManager } from '@tanstack/query-core'
33
import { useIsRestoring } from './useIsRestoring.js'
44
import { useQueryClient } from './useQueryClient.js'
5-
import { isSvelteStore } from './utils.js'
5+
import { isSvelteStore, noop } from './utils.js'
66
import type {
77
QueryClient,
88
QueryKey,
@@ -66,7 +66,7 @@ export function createBaseQuery<
6666
QueryObserverResult<TData, TError>
6767
>(isRestoring, ($isRestoring, set) => {
6868
const unsubscribe = $isRestoring
69-
? () => undefined
69+
? noop
7070
: observer.subscribe(notifyManager.batchCalls(set))
7171
observer.updateResult()
7272
return unsubscribe

packages/svelte-query/src/createQueries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { QueriesObserver, notifyManager } from '@tanstack/query-core'
22
import { derived, get, readable } from 'svelte/store'
33
import { useIsRestoring } from './useIsRestoring.js'
44
import { useQueryClient } from './useQueryClient.js'
5-
import { isSvelteStore } from './utils.js'
5+
import { isSvelteStore, noop } from './utils.js'
66
import type { Readable } from 'svelte/store'
77
import type { StoreOrVal } from './types.js'
88
import type {
@@ -253,7 +253,7 @@ export function createQueries<
253253

254254
const result = derived([isRestoring], ([$isRestoring], set) => {
255255
const unsubscribe = $isRestoring
256-
? () => undefined
256+
? noop
257257
: observer.subscribe(notifyManager.batchCalls(set))
258258

259259
return () => unsubscribe()

0 commit comments

Comments
 (0)