When using typescript there are two issues. Once when using the syntax from the prefetching docs: https://www.smooth-code.com/open-source/loadable-components/docs/prefetching/ and the other when trying to preload.
// Argument of type '() => string' is not assignable to parameter of type '(props: {}) => Promise<DefaultComponent<{}>>'.
// Type 'string' is not assignable to type 'Promise<DefaultComponent<{}>>'.
export const User = () => loadable(() => './User')
and
export const User = () => loadable(() => import('./User'))
// Property 'preload' does not exist on type '() => ComponentType<{ fallback?: Element | undefined; }>'.
User.preload()
Typescript should not error and docs should be updated
## System:
- OS: Linux 4.4 Ubuntu 16.04.2 LTS (Xenial Xerus)
- CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
- Memory: 8.81 GB / 15.95 GB
- Shell: 4.3.46 - /bin/bash
## Binaries:
- Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
- Yarn: 1.9.4 - ~/.yarn/bin/yarn
- npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
Hello @bitttttten, thanks for your report.
Help is needed here, could someone please update TypeScript types ? Thanks!
@theKashey I guess?
:working:
Ah I didn't realise the preload method was reasonably new too. I was actually on 5.5.0 at the time.
That's quite strange, but there are type definitions?
Nor here, nor in DefinitelyTypes. All I found is https://github.com/DefinitelyTyped/DefinitelyTyped/tree/f37d7b008ce2c4ecbbbc4bee009fb3f03d639268/types/loadable__component, which is for older versions.
There are type definitions but they have not been updated since the release that was 2 weeks ago.
@bitttttten - so where is that there
Looks like this can be closed now: https://github.com/DefinitelyTyped/DefinitelyTyped/commit/062bc01af259fdf566bb5922482cb9d4af7426e8
Most helpful comment
:working: