2

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

Bahram
  • 1,464
  • 2
  • 22
  • 38
  • @lonut, maybe, but from reactks.org it seems that lazy should be available react package itself, import React, {lazy, Suspense} from 'react'; from https://reactjs.org/blog/2018/10/23/react-v-16-6.html – Bahram Nov 08 '18 at 13:28
  • @Think-Twice, react version that I use is 16.6.1 ( "react": "^16.6.1",) – Bahram Nov 08 '18 at 13:29
  • Looks like from the error, typescript yet to support react v16.6.0 because lazy is included in react v16.6.0. The error thrown from @types library – Hemadri Dasari Nov 08 '18 at 13:30
  • @Think-Twice, as I understand, I should wait for typescript support ?!!! – Bahram Nov 08 '18 at 13:38
  • Yes it looks like typescript yet to support react v16.6.0 – Hemadri Dasari Nov 08 '18 at 13:41
  • 1
    TypeDef is updated: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L1 – jakobdo Nov 17 '18 at 21:37

2 Answers2

5

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

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

Olaf
  • 501
  • 4
  • 7
1

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