[英]Why do I get ':' expected.ts(1005) as a Typescript error?
在我的 Next.js 項目的登錄頁面上的 handleLogin function 中,我收到此 Typesricpt 錯誤:':' expected.ts(1005)
這是應該處理登錄的 function:
const handleLogin = useCallback(async (credentials) => {
if (!credentials.email) {
return setError('email is missing')
}
if (!credentials.password) {
return setError('password is missing')
}
try {
setLoading(true)
const response: SignInResponse | undefined = await signIn('credentials', { ...credentials, redirect: false })
if (response?error && response.error === 'CredentialsSignin') {
setError('email or password are wrong')
} else {
setError('')
router.push('/')
}
} catch {
setError('login failed')
} finally {
setLoading(false)
console.log(error)
}
}, [router, error])
我不知道這個錯誤出現了。
我認為你有一個錯字。
條件看起來像一個三元或條件運算符( a? b: c
)所以下面的行需要冒號:
response?error && response.error === 'CredentialsSignin'
但是,這不是您想要的。 我認為你有一個錯字,而是想要可選的鏈接:
response?.error && response.error === 'CredentialsSignin'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.