diff --git a/types/next-server/tsconfig.json b/types/next-server/tsconfig.json index 119b4acb93..f05382ea65 100644 --- a/types/next-server/tsconfig.json +++ b/types/next-server/tsconfig.json @@ -35,6 +35,6 @@ "test/next-server-dynamic-tests.tsx", "test/next-server-router-tests.tsx", "test/imports/no-default.tsx", - "test/imports/with-default.tsx", + "test/imports/with-default.tsx" ] } diff --git a/types/next/test/imports/no-default.tsx b/types/next/test/imports/no-default.tsx new file mode 100644 index 0000000000..1f406a3fe3 --- /dev/null +++ b/types/next/test/imports/no-default.tsx @@ -0,0 +1,7 @@ +import * as React from "react"; + +interface Props { + foo: string; +} + +export const MyComponent: React.SFC = ({ foo: text }) => {text}; diff --git a/types/next/test/imports/with-default.tsx b/types/next/test/imports/with-default.tsx new file mode 100644 index 0000000000..f448a16680 --- /dev/null +++ b/types/next/test/imports/with-default.tsx @@ -0,0 +1,11 @@ +import * as React from "react"; + +interface Props { + foo: boolean; +} + +export default class MyComponent extends React.Component { + render() { + return this.props.foo ?
: null; + } +} diff --git a/types/next/test/next-dynamic-tests.tsx b/types/next/test/next-dynamic-tests.tsx index 3e929e5cd0..a291c6ae7d 100644 --- a/types/next/test/next-dynamic-tests.tsx +++ b/types/next/test/next-dynamic-tests.tsx @@ -5,7 +5,7 @@ import dynamic, { LoadingComponentProps } from "next/dynamic"; interface MyComponentProps { foo: string; } -const MyComponent: React.FunctionComponent = () =>
I'm async!
; +const MyComponent: React.StatelessComponent = () =>
I'm async!
; const asyncComponent = Promise.resolve(MyComponent); // Examples from @@ -17,17 +17,33 @@ const LoadingComponent: React.StatelessComponent = ({ }) =>

loading...

; // 1. Basic Usage (Also does SSR) -const DynamicComponent = dynamic(asyncComponent); +const DynamicComponent = dynamic(Promise.resolve(MyComponent)); const dynamicComponentJSX = ; +// 1.1 Basic Usage (Loader function, module shape with 'export = Component' / 'module.exports = Component') +const DynamicComponent2 = dynamic(() => Promise.resolve(MyComponent)); +const dynamicComponent2JSX = ; + +// 1.2 Basic Usage (Loader function, module shape with 'export default Component') +const DynamicComponent3 = dynamic(() => Promise.resolve({ default: MyComponent })); +const dynamicComponent3JSX = ; + +// TODO: Work with module shape 'export { Component }' + // 2. With Custom Loading Component -const DynamicComponentWithCustomLoading = dynamic(asyncComponent, { +const DynamicComponentWithCustomLoading = dynamic(import('./imports/with-default'), { loading: LoadingComponent }); -const dynamicComponentWithCustomLoadingJSX = ; +const dynamicComponentWithCustomLoadingJSX = ; + +// 2.1. With Custom Loading Component (() => import('') syntax) +const DynamicComponentWithCustomLoading2 = dynamic(() => import('./imports/with-default'), { + loading: LoadingComponent +}); +const dynamicComponentWithCustomLoading2JSX = ; // 3. With No SSR -const DynamicComponentWithNoSSR = dynamic(asyncComponent, { +const DynamicComponentWithNoSSR = dynamic(() => import('./imports/with-default'), { ssr: false }); @@ -35,8 +51,8 @@ const DynamicComponentWithNoSSR = dynamic(asyncComponent, { const HelloBundle = dynamic({ modules: () => { const components = { - Hello1: asyncComponent, - Hello2: asyncComponent + Hello1: () => import('./imports/with-default'), + Hello2: () => import('./imports/with-default') }; return components; @@ -53,7 +69,7 @@ const helloBundleJSX = ; // 5. With plain Loadable options const LoadableComponent = dynamic({ - loader: () => asyncComponent, + loader: () => import('./imports/with-default'), loading: LoadingComponent, delay: 200, timeout: 10000 diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index 9981affbd3..3dec431b0c 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -38,6 +38,8 @@ "test/next-link-tests.tsx", "test/next-dynamic-tests.tsx", "test/next-router-tests.tsx", - "test/next-component-tests.tsx" + "test/next-component-tests.tsx", + "test/imports/no-default.tsx", + "test/imports/with-default.tsx" ] }