我正在学习F#,但我很难理解这一点:
let allPrimes =
let rec allPrimes' n =
seq {
if isPrime n then
yield n
yield! allPrimes' (n + 1) }
allPrimes' 2
Run Code Online (Sandbox Code Playgroud)
yield!即使我读过其他更简单的例子,我也无法弄清楚算子究竟做了什么,它似乎yield!返回了一个内部序列.
我正在尝试使用 TypeScript 遵循下一个身份验证文档。使用以下代码和_app.tsx文档中的一些代码我可以保护页面:
AdminDashboard.auth = {
role: "admin",
loading: <AdminLoadingSkeleton />,
unauthorized: "/login-with-different-user", // redirect to this url
}
Run Code Online (Sandbox Code Playgroud)
使用 TypeScript 实现此目的的正确方法是什么?
我找到了一个有效的解决方案,但我不确定这是否是正确的方法:
export type NextPageWithAuth = NextPage & {
auth: boolean,
role: string
}
type NextPageAuthProps = {
Component: NextPageWithAuth,
pageProps: any
}
Run Code Online (Sandbox Code Playgroud)
该AppProps类型比我自己的类型复杂得多NextPageAuthProps。