#Type argument to function wrapping dynamic import

4 messages · Page 1 of 1 (latest)

quick oxide
#

I'm trying to wrap up a dynamic import so that it is easier for folks to get consistent predictable behaviour from. I Cannot work out the argument type for import; as everything says it is a string, but it clearly has a type, which the compiler knows to check if can be included. I just dont want to lose that in making others lives easier.

playground link I think this may be that the import type functionality is not exported

slate otterBOT
#

@quick oxide Here's a shortened URL of your playground link! You can remove the full link from your message.

loui1986#0

Preview:```ts
import { lazy, ComponentType, LazyExoticComponent, Suspense } from 'react';

const LazyComponent = lazy(() => import('@/components/something').then((module) => ({
default: module.Component
})));

/**

  • Create a lazy React component by module path + export name.
    ...```
shell glen
#

TS simply doesn't support resolving the type of import(DynamicType).

#

You have to change your API to a different shape so TS can resolve it, maybe something like:

lazyRemoteComponent(() => import('@/components/something'), 'Component')