How do I use React 15.5 with TypeScript?

What's the correct way to use TypeScript and React together, now that they've extracted PropTypes in a separate project with version 15.5?

Everything works fine after upgrading from 15.4 to 15.5, except I now get this warning in the console: "Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead."

How do I make it disappear?

I tried the following steps but it doesn't remove the console warning.

  • Add packages prop-types

    and @types/prop-types

    .
  • Import PropTypes wherever I import the React, import * as PropTypes from "proptypes"

    . Also tried with help require("prop-types")

    .
  • Disable noUnusedLocals

    to avoid compiler not using PropTypes.

But . Since I'm using TypeScript, the compiler checks the PropTypes at compile time, so I don't need to do the same at runtime, and so I shouldn't get a warning at all, should I? I hope that maybe I can add or change a setting somewhere in the build config that will cause React to compile without PropTypes.

+3


source to share


2 answers


Figured out: this mobx-react-devtools

is causing the warning. The question has been posted and corrected, but apparently hasn't been released yet.



https://github.com/mobxjs/mobx-react-devtools/issues/59

+2


source


I had the same problem because I imported React like:

import * as React from 'react'

      

After I changed it to:

 import React from 'react'

      



everywhere in my project the warning disappeared.

No package needed prop-types

.

PS I am using babel and has "allowSyntheticDefaultImports": true

in tsconfig.json.

+3


source







All Articles