-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: types from 'any' to 'unknown' #3062
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
Changes from all commits
44fff3b
2d4bf9d
c1bf1c6
3b07168
317cfd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ import { | |
| * @param fn - object to test | ||
| * @returns true if `fn` is a StoreDefinition | ||
| */ | ||
| export const isUseStore = (fn: any): fn is StoreDefinition => { | ||
| export const isUseStore = (fn: unknown): fn is StoreDefinition | ||
| return typeof fn === 'function' && typeof fn.$id === 'string' | ||
| } | ||
|
|
||
|
|
@@ -30,9 +30,9 @@ export const isUseStore = (fn: any): fn is StoreDefinition => { | |
| * @returns - newState | ||
| */ | ||
| export function patchObject( | ||
| newState: Record<string, any>, | ||
| oldState: Record<string, any> | ||
| ): Record<string, any> { | ||
| newState: Record<string, unknown>, | ||
| oldState: Record<string, unknown> | ||
| ): Record<string, unknown> { | ||
| // no need to go through symbols because they cannot be serialized anyway | ||
| for (const key in oldState) { | ||
| const subPatch = oldState[key] | ||
|
|
@@ -79,12 +79,12 @@ export function acceptHMRUpdate< | |
| S extends StateTree = StateTree, | ||
| G extends _GettersTree<S> = _GettersTree<S>, | ||
| A = _ActionsTree, | ||
| >(initialUseStore: StoreDefinition<Id, S, G, A>, hot: any) { | ||
| >(initialUseStore: StoreDefinition<Id, S, G, A>, hot: unknown) { | ||
| // strip as much as possible from iife.prod | ||
| if (!__DEV__) { | ||
| return () => {} | ||
| } | ||
|
Comment on lines
+82
to
86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeScript error: accessing properties on Changing Consider these options: Option 1: Keep ->(initialUseStore: StoreDefinition<Id, S, G, A>, hot: unknown) {
+>(initialUseStore: StoreDefinition<Id, S, G, A>, hot: any) {Option 2: Define a proper type for the HMR API: interface HotModuleAPI {
data: Record<string, any>
invalidate(): void
}
export function acceptHMRUpdate<...>(
initialUseStore: StoreDefinition<Id, S, G, A>,
hot: HotModuleAPI
) {Option 3: Add runtime narrowing (if you want to keep >(initialUseStore: StoreDefinition<Id, S, G, A>, hot: unknown) {
if (!hot || typeof hot !== 'object') return () => {}
if (!('data' in hot) || !('invalidate' in hot)) return () => {}
// ... rest of implementation with type assertions🤖 Prompt for AI Agents |
||
| return (newModule: any) => { | ||
| return (newModule: unknown) => { | ||
| const pinia: Pinia | undefined = hot.data.pinia || initialUseStore._pinia | ||
|
|
||
| if (!pinia) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify TypeScript compilation with property access on
unknown.While changing the parameter to
unknownimproves type safety, accessingfn.$idafter only checkingtypeof fn === 'function'may cause a TypeScript error. TypeScript doesn't infer that functions can have custom properties without additional narrowing.Run the following to verify compilation:
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 3884
🏁 Script executed:
Length of output: 3884
Fix syntax error: missing opening brace in
isUseStorefunction signature.The function at line 19 is missing the opening brace
{after the type predicate. The line break splits the signature from the body:Additionally, accessing
fn.$idon a narrowedFunctiontype creates a type safety issue—functions don't have a$idproperty by default. Consider either casting to a more specific type or using optional chaining if runtime safety is intended.🧰 Tools
🪛 Biome (2.1.2)
[error] 20-20: Line terminator not permitted before arrow.
(parse)
[error] 20-21: Expected a statement but instead found '}'.
Expected a statement here.
(parse)
🤖 Prompt for AI Agents