1. 场景复现
(1)新建项目
$ mkdir test-jsx && cd test-jsx
$ npm init -f
$ npm i -S antd@3.13.2
(2)新建index.jsx文件
import * as React from 'react';
import { Table } from 'antd';
<Table
pagination
/>
结果,当pagination
类型不匹配时并没有报错。

2. 原因
对于js以及jsx文件,vs code只会进行类型提示,而不会报错。
3. 解决方案
3.1 方法一
(1)配置jsconfig.json
{
"exclude":[
"node_modules"
],
"compilerOptions": {
"checkJs": true
}
}
注:这个jsconfig.json应放到vs code项目根目录下。
(2)重启vs code

3.2 方法二
(1)使用tsx
将index.jsx改成index.tsx
并安装以下依赖
$ npm i -S react@16.8.1 @types/react@16.8.2
(2)重启vs code

网友评论