reactjstypescriptreact-16

React lazy in typescript


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


Solution

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

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