TypeScript不要检查React道具

时间:2016-12-25 10:09:05

标签: javascript reactjs typescript

我开始将我的React项目迁移到TypeScript并且几乎不需要帮助。当我编译测试组件道具检查不工作时。

TypeScript 2.1.4

Component.tsx

import * as React from 'react';
import * as ReactDOM from 'react-dom';

interface IPlayProps {
    status: string,
    addClass: string
}

class Play extends React.Component<IPlayProps, any> {
    render() {
        return (
            <div>{this.props.addClass}</div>
        );
    }
}

ReactDOM.render(
    <Play addClass={0} />,
    document.getElementById('app')
);

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "noImplicitAny": false,
    "sourceMap": false,
    "allowJs": true,
    "importHelpers": true,
    "removeComments": true,
    "jsx": "react",
    "outDir": "./compiled/"
  },
  "include": [
    "resources/scripts/player/globals.d.ts",
    "resources/scripts/player/components/footer/Play.tsx"
  ]
}

typings.json

{
  "dependencies": {
    "react": "registry:npm/react#15.0.1+20160601175240",
    "react-dom": "registry:npm/react-dom#15.0.1+20160826174104"
  },
  "globalDependencies": {
    "file-saver": "registry:dt/file-saver#0.0.0+20161106021201",
    "jquery": "registry:dt/jquery#1.10.0+20161119044246",
    "underscore": "registry:dt/underscore#1.8.3+20161123125004",
    "x2js": "registry:dt/x2js#0.0.0+20160510002910"
  }
}

globals.d.ts

/// <reference path="../../../typings/main.d.ts" />
/// <reference path="../../../typings/index.d.ts" />

使用错误的道具类型渲染组件

<Play addClass={0} />

终端没有错误,为什么?

0 个答案:

没有答案