Unverified Commit 7f09df34 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix typings of dynamic suspense (#28740)

x-ref: https://github.com/vercel/next.js/pull/27611#issuecomment-911743160
parent e00b9467
......@@ -33,17 +33,18 @@ export type LoadableBaseOptions<P = {}> = LoadableGeneratedOptions & {
ssr?: boolean
}
export type LoadableSuspenseOptions<P = {}> = {
loader: Loader<P>
export type LoadableSuspenseOptions = {
suspense?: boolean
}
export type LoadableOptions<P = {}> = LoadableBaseOptions<P>
export type DynamicOptions<P = {}> = LoadableBaseOptions<P>
export type DynamicOptions<P = {}> =
| LoadableBaseOptions<P>
| LoadableSuspenseOptions
export type LoadableFn<P = {}> = (
opts: LoadableOptions<P> | LoadableSuspenseOptions<P>
opts: LoadableOptions<P> | LoadableSuspenseOptions
) => React.ComponentType<P>
export type LoadableComponent<P = {}> = React.ComponentType<P>
......@@ -113,7 +114,9 @@ export default function dynamic<P = {}>(
// Support for passing options, eg: dynamic(import('../hello-world'), {loading: () => <p>Loading something</p>})
loadableOptions = { ...loadableOptions, ...options }
const suspenseOptions = loadableOptions as LoadableSuspenseOptions<P>
const suspenseOptions = loadableOptions as LoadableSuspenseOptions & {
loader: Loader<P>
}
if (!process.env.__NEXT_CONCURRENT_FEATURES) {
// Error if react root is not enabled and `suspense` option is set to true
if (!process.env.__NEXT_REACT_ROOT && suspenseOptions.suspense) {
......
export default function TsFoo() {
return <div>ts-foo</div>
}
import React, { Suspense } from 'react'
import dynamic from 'next/dynamic'
const DynamicFoo = dynamic(() => import('../../components/ts-foo'), {
suspense: true,
})
export default function Typing() {
return (
<Suspense fallback={null}>
<DynamicFoo />
</Suspense>
)
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment