Skip to content

Commit 18ccc00

Browse files
committed
refactor: identity fn
1 parent 08dfd9e commit 18ccc00

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { identityFn } from '../../../utils'
12
import { encodeParam } from '../../../encoding'
23
import { warn } from '../../../warning'
34
import { decode, MatcherQueryParams } from '../resolver-abstract'
@@ -289,13 +290,10 @@ export class MatcherPatternPathCustomParams<
289290
var currentMatch = (match[i + 1] as string | undefined) ?? null
290291

291292
var value = paramOptions.repeat
292-
? (currentMatch?.split('/') || []).map(
293-
// using just decode makes the type inference fail
294-
v => decode(v)
295-
)
293+
? (currentMatch?.split('/') || []).map<string>(decode)
296294
: decode(currentMatch)
297295

298-
params[paramName] = (paramOptions.get || (v => v))(
296+
params[paramName] = (paramOptions.get || identityFn)(
299297
value
300298
// NOTE: paramName and paramOptions are not connected from TS point of view
301299
)
@@ -325,7 +323,7 @@ export class MatcherPatternPathCustomParams<
325323
const paramName = this.paramsKeys[paramIndex++]
326324
const paramOptions = this.params[paramName]
327325
const value: ReturnType<NonNullable<Param_GetSet['set']>> = (
328-
paramOptions.set || (v => v)
326+
paramOptions.set || identityFn
329327
)(params[paramName])
330328

331329
return Array.isArray(value)

packages/router/src/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import {
55
RawRouteComponent,
66
} from '../types'
77

8+
/**
9+
* Identity function that returns the value as is.
10+
*
11+
* @param v - the value to return
12+
*
13+
* @internal
14+
*/
15+
export const identityFn = <T>(v: T) => v
16+
817
export * from './env'
918

1019
/**

0 commit comments

Comments
 (0)