我是打字稿的新手,我真的希望我的 mount 初始化设置为 true,有谁知道为什么它只会让我将其设置为 false?这是错误:
Type '{ children: Element; appId: string | undefined; serverUrl: string | undefined; initializeOnMount: true; }' is not assignable to type 'IntrinsicAttributes & MoralisProviderProps'.
Types of property 'appId' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2322)
MoralisProvider 的类型签名是
const MoralisProvider: ({ children, appId: _appId, serverUrl: _serverUrl, jsKey, dangerouslyUseOfMasterKey, plugins, environment, getMoralis, options: { onAccountChanged },
initializeOnMount, }: MoralisProviderProps) => JSX.Element
组件安装代码
import MoralisProvider
import type { AppProps } from 'next/app';
import { MoralisProvider } from 'react-moralis';
function MyApp({ Component, pageProps }: AppProps) {
return (
<MoralisProvider
appId={process.env.NEXT_PUBLIC_MORALIS_APP_ID}
serverUrl={process.env.NEXT_PUBLIC_MORALIS_SERVER_ID}
initializeOnMount
>
<Component {...pageProps} />
</MoralisProvider>)
}
export default MyApp;