React lazy in typescript

2.5k views Asked by At

I've just updated my create-react-app to version 2.1.1 which adds support for typescript (check it out).

by command npx create-react-app my-app --typescript, one can create a react app with typescript by default, but adding lazy

import React, { Component, lazy} from 'react';

cause this error

Type error: Module '".../node_modules/@types/react/index"' 
has no exported member 'lazy'.  TS2305

Probably I'm missing something here

Thanks

2

There are 2 answers

0
Olaf On BEST ANSWER

Long story short, You need to wait for support from @types/react maintainers.

There are the links to the corresponding issues - here and here.

0
Arash Kadkhodaei On

@types/react hase been released for react v16.6 and v16.7 just upgrade @types/react to use new React type definition