// 'HelloProps' describes the shape of props. // State is never set so we use the 'undefined' type. export class Hello extends React.Component<HelloProps, undefined> { render() { return <h1>Hello from {this.props.compiler} and {this.props.framework}!</h1>; } }
在使用Hello时,编辑器会分析其props的类型信息,并在你书写JSX的时候给予提示。非常的爽。
1 2 3 4 5 6 7 8 9
import * as React from "react"; import * as ReactDOM from "react-dom";
// Enable sourcemaps for debugging webpack's output. devtool: "source-map",
resolve: { // Add '.ts' and '.tsx' as resolvable extensions. extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"] },
module: { loaders: [ // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'. { test: /\.tsx?$/, loader: "awesome-typescript-loader" }, { test: /\.css$/, loaders: ["style-loader", "css-loader?sourceMap"] } ],
preLoaders: [ // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. { test: /\.js$/, loader: "source-map-loader" } ] },
// When importing a module whose path matches one of the following, just // assume a corresponding global variable exists and use that instead. // This is important because it allows us to avoid bundling all of our // dependencies, which allows browsers to cache those libraries between builds. externals: { "react": "React", "react-dom": "ReactDOM" }, };