fix(lib/utils/proxy)!: disallow passing type-strings to ProxifyOptions.hint
This commit is contained in:
parent
c331f1fb84
commit
996e4f5994
10 changed files with 23 additions and 36 deletions
|
|
@ -48,7 +48,7 @@ export let ActionSheetActionCreators: DiscordModules.Actions.ActionSheetActionCr
|
|||
if (module) return (ActionSheetActionCreators = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators =
|
|||
if (module) return (AlertActionCreators = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
|
|
|
|||
|
|
@ -51,5 +51,5 @@ export let Constants: DiscordModules.Constants = proxify(
|
|||
|
||||
if (module) return (Constants = module)
|
||||
},
|
||||
{ hint: 'object' },
|
||||
{ hint: {} },
|
||||
)!
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export let Design: Design = proxify(
|
|||
if (module) return (Design = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,6 @@ export let RootNavigationRef: RootNavigationRef = proxify(
|
|||
if (module) return (RootNavigationRef = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
|
|
|||
|
|
@ -42,6 +42,6 @@ export let SettingListRenderer: SettingListRenderer = proxify(
|
|||
if (module) return (SettingListRenderer = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
|
|
|||
2
lib/externals/src/browserify.ts
vendored
2
lib/externals/src/browserify.ts
vendored
|
|
@ -27,6 +27,6 @@ export let nodeUtil: typeof import('node:util') = proxify(
|
|||
if (module) return (nodeUtil = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
|
|
|||
6
lib/externals/src/react-native-clipboard.ts
vendored
6
lib/externals/src/react-native-clipboard.ts
vendored
|
|
@ -45,13 +45,13 @@ let ClipboardModule: typeof import('@react-native-clipboard/clipboard') =
|
|||
if (module) return (ClipboardModule = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
export const { useClipboard } = destructure(ClipboardModule, {
|
||||
hint: 'function',
|
||||
hint: () => {},
|
||||
})
|
||||
export const { default: Clipboard } = destructure(ClipboardModule, {
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
})
|
||||
|
|
|
|||
4
lib/externals/src/react-navigation.ts
vendored
4
lib/externals/src/react-navigation.ts
vendored
|
|
@ -36,7 +36,7 @@ export let ReactNavigationNative: typeof import('@react-navigation/native') =
|
|||
if (module) return (ReactNavigationNative = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ export let ReactNavigationStack: typeof import('@react-navigation/stack') =
|
|||
if (module) return (ReactNavigationStack = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
||||
|
|
|
|||
2
lib/externals/src/shopify.ts
vendored
2
lib/externals/src/shopify.ts
vendored
|
|
@ -37,6 +37,6 @@ export let FlashList: typeof import('@shopify/flash-list') = proxify(
|
|||
if (module) return (FlashList = module)
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
hint: {},
|
||||
},
|
||||
)!
|
||||
|
|
|
|||
|
|
@ -83,9 +83,9 @@ export interface ProxifyOptions {
|
|||
/**
|
||||
* The hint for the proxified value.
|
||||
*
|
||||
* @default 'function'
|
||||
* @default function () {}
|
||||
*/
|
||||
hint?: 'object' | 'function' | object
|
||||
hint?: object
|
||||
/**
|
||||
* Whether the proxified value should be cached.
|
||||
*/
|
||||
|
|
@ -108,7 +108,7 @@ export interface ProxifyOptions {
|
|||
*
|
||||
* @example Without cache
|
||||
* ```ts
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: 'object' })
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: {} })
|
||||
* console.log(proxified) // { value: 0.123 }
|
||||
* console.log(proxified.value) // 0.456
|
||||
* console.log(proxified) // { value: 0.789 }
|
||||
|
|
@ -116,28 +116,15 @@ export interface ProxifyOptions {
|
|||
*
|
||||
* @example With cache
|
||||
* ```ts
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: 'object', cache: true })
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: {}, cache: true })
|
||||
* console.log(proxified) // { value: 0.123 }
|
||||
* console.log(proxified.value) // 0.123
|
||||
* console.log(proxified) // { value: 0.123 }
|
||||
* ```
|
||||
*/
|
||||
export function proxify<T>(signal: () => T, options?: ProxifyOptions): T {
|
||||
let hint: any
|
||||
|
||||
switch (options?.hint) {
|
||||
case undefined:
|
||||
case 'function':
|
||||
// biome-ignore lint/complexity/useArrowFunction: We need a function with a constructor
|
||||
hint = function () {}
|
||||
break
|
||||
case 'object':
|
||||
hint = {}
|
||||
break
|
||||
default:
|
||||
hint = options!.hint
|
||||
break
|
||||
}
|
||||
// biome-ignore lint/complexity/useArrowFunction: We need a function with a constructor
|
||||
const hint = options?.hint ?? function () {}
|
||||
|
||||
_metas.set(hint, [
|
||||
signal,
|
||||
|
|
@ -150,7 +137,7 @@ export function proxify<T>(signal: () => T, options?: ProxifyOptions): T {
|
|||
if (v == null) DEBUG_warnNullishProxifiedValue()
|
||||
}
|
||||
|
||||
return new Proxy(hint, _handler)
|
||||
return new Proxy(hint, _handler) as T
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -165,7 +152,7 @@ export function proxify<T>(signal: () => T, options?: ProxifyOptions): T {
|
|||
*
|
||||
* @example Without cache
|
||||
* ```ts
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: 'object' })
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: {} })
|
||||
* const x = unproxify(proxified)
|
||||
* console.log(x) // { value: 0.123 }
|
||||
* console.log(x.value) // 0.123
|
||||
|
|
@ -174,7 +161,7 @@ export function proxify<T>(signal: () => T, options?: ProxifyOptions): T {
|
|||
*
|
||||
* @example With cache
|
||||
* ```ts
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: 'object', cache: true })
|
||||
* const proxified = proxify(() => ({ value: Math.random() }), { hint: {}, cache: true })
|
||||
* const x = unproxify(proxified)
|
||||
* console.log(x) // { value: 0.123 }
|
||||
* console.log(x.value) // 0.123
|
||||
|
|
@ -209,7 +196,7 @@ function unproxifyFromHint(hint: object) {
|
|||
* // cache is not turned on, so each access will call the signal again
|
||||
* const { x, y } = destructure(
|
||||
* proxify(() => ({ x: Math.random(), y: [Math.random()], z: null })),
|
||||
* { hint: 'object' }
|
||||
* { hint: {} }
|
||||
* )
|
||||
*
|
||||
* // Non-nullish primitives are not proxifiable
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue