Definitelytyped: [@types/react] Add properties Suspense & lazy

Created on 25 Oct 2018  路  7Comments  路  Source: DefinitelyTyped/DefinitelyTyped

React v.16.6 has been released and it brings lazy and Suspense.

Running tsc --build tsconfig.json throws:

src/components/DynamicComponent/index.tsx:28:24 - error TS2339: Property 'lazy' does not exist on type 'typeof React'.                                                      

28       component: React.lazy(() => import(this.state.url)),
                          ~~~~

src/components/DynamicComponent/index.tsx:46:14 - error TS2339: Property 'Suspense' does not exist on type 'typeof React'.

46       <React.Suspense fallback={<div>Loading...</div>}>
                ~~~~~~~~

src/components/DynamicComponent/index.tsx:55:15 - error TS2339: Property 'Suspense' does not exist on type 'typeof React'.

55       </React.Suspense>
                 ~~~~~~~~

@johnnyreilly @bbenezech @pzavolinsky

Most helpful comment

@dbchristopher This did not work for me so I used another workaround:

import React from "react";
const Suspense = (React as any).Suspense;
const lazy = (React as any).lazy;

All 7 comments

After being blocked by this, I took the less-than-ideal approach of simply adding // @ts-ignore before the React import

// @ts-ignore
import React, { Suspense, lazy } from 'react';

As per https://twitter.com/martin_hotell/status/1055381631094190080, it sounds like it will be a while before we get official types for React 16.6. I'd prefer to have access to lazy and Suspense until then.

I want to make use of the new ExoticComponent definition in #29990 to add the other new types, so this might have to wait until it is merged.

Had no opportunity to test this out yet, but I am wondering, is lazy loaded component properly inferred for prop types?

It does work locally 馃槆

image

@dbchristopher This did not work for me so I used another workaround:

import React from "react";
const Suspense = (React as any).Suspense;
const lazy = (React as any).lazy;

This was added in #30054.

@arkon You're right, will close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csharpner picture csharpner  路  3Comments

ArtemZag picture ArtemZag  路  3Comments

jrmcdona picture jrmcdona  路  3Comments

Loghorn picture Loghorn  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments