typescript - ts(2769) 在 Pinia 儲存中對 Ref 使用 $patch 時沒有符合的重載呼叫
我在 TypeScript 問題上卡住了。程式碼其實是可以運作的,只是 IDE 對我使用 pinia 的 $patch 函數時拋出了錯誤。
這是我的商店:
import { AuthenticationResult } from '@azure/msal-browser'
import { defineStore } from 'pinia'
import { ref } from 'vue'
const useAuthStore = defineStore('auth', () => {
const details = ref<AuthenticationResult>()
return { details }
})
export default useAuthStore
這是我嘗試修改 details 屬性的程式碼:
const tokenResponse: AuthenticationResult = await instance.acquireTokenSilent(loginRedirectRequest)
const authStore = useAuthStore()
authStore.$patch({
details: tokenResponse
})
我收到的錯誤如下所示:
No overload matches this call.
Overload 1 of 2, '(partialState: _DeepPartial<{ details: { authority: string; uniqueId: string; tenantId: string; scopes: string[]; account: { homeAccountId: string; environment: string; tenantId: string; username: string; localAccountId: string; name?: string | undefined; idTokenClaims?: { ...; } | undefined; nativeAccountId?: string | undefined; } | null; ... 13 more ...; fromNativeBroker?: boolean | undefined; } | undefined; }>): void', gave the following error.
Overload 2 of 2, '(stateMutator: (state: { details: { authority: string; uniqueId: string; tenantId: string; scopes: string[]; account: { homeAccountId: string; environment: string; tenantId: string; username: string; localAccountId: string; name?: string | undefined; idTokenClaims?: { ...; } | undefined; nativeAccountId?: string | undefined; } | null; ... 13 more ...; fromNativeBroker?: boolean | undefined; } | undefined; }) => any): void', gave the following error.ts(2769)
useAuthStore.ts(8, 12): The expected type comes from property 'details' which is declared here on type '_DeepPartial<{ details: { authority: string; uniqueId: string; tenantId: string; scopes: string[]; account: { homeAccountId: string; environment: string; tenantId: string; username: string; localAccountId: string; name?: string | undefined; idTokenClaims?: { ...; } | undefined; nativeAccountId?: string | undefined; ...'
