The simplest example Typescript + React + WebPack generates errors

When I compile a simple React / Typescript application (shown below), I get a lot of compiler warnings that don't appear in my code.

/// <reference path="main/ambient/react-dom/index.d.ts" />
/// <reference path="main/ambient/react/index.d.ts" />

import * as React from "react";
import { render } from "react-dom";

class Example extends React.Component<any, any> {
  render() {
    return <p> Hello! </p>;
  }
}

render(<Example />, document.getElementById("root"));

Although this example runs after compilation (via WebPack), it generates the following errors:

(19,22): error TS2339: Property 'createElement' does not exist on type '{}'.
(22,9): error TS2339: Property 'Component' does not exist on type '{}'.
(23,13): error TS2339: Property 'render' does not exist on type '{}'.
(23,26): error TS2339: Property 'createElement' does not exist on type '{}'.

I am running React v0.14.8. I use these typings for React , and these typings for React-dom enter the link here

My question is: Why does this example generate so many errors? How can I fix these errors?

Requested: tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react"
  },

  "exclude": [
    "node_modules",
    "typings/browser",
    "typings/browser.d.ts"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}
+4
source share
2 answers

. WebPack (new webpack.optimize.OccurenceOrderPlugin()). .

+1

typings . TypeScript React

0

All Articles